結果
問題 | No.1407 Kindness |
ユーザー | yagisumi |
提出日時 | 2021-04-02 01:16:05 |
言語 | TypeScript (5.4.3) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 3,269 bytes |
コンパイル時間 | 10,172 ms |
コンパイル使用メモリ | 256,824 KB |
実行使用メモリ | 54,012 KB |
最終ジャッジ日時 | 2023-08-23 08:09:12 |
合計ジャッジ時間 | 16,587 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
44,272 KB |
testcase_01 | AC | 80 ms
42,216 KB |
testcase_02 | AC | 81 ms
42,288 KB |
testcase_03 | AC | 82 ms
42,232 KB |
testcase_04 | AC | 82 ms
44,280 KB |
testcase_05 | AC | 82 ms
42,348 KB |
testcase_06 | AC | 81 ms
42,204 KB |
testcase_07 | AC | 80 ms
42,336 KB |
testcase_08 | AC | 80 ms
42,212 KB |
testcase_09 | AC | 82 ms
42,208 KB |
testcase_10 | AC | 83 ms
42,368 KB |
testcase_11 | AC | 82 ms
44,256 KB |
testcase_12 | AC | 144 ms
52,244 KB |
testcase_13 | AC | 118 ms
48,548 KB |
testcase_14 | AC | 119 ms
48,664 KB |
testcase_15 | AC | 137 ms
52,096 KB |
testcase_16 | AC | 126 ms
51,420 KB |
testcase_17 | AC | 121 ms
48,784 KB |
testcase_18 | AC | 119 ms
48,564 KB |
testcase_19 | AC | 141 ms
54,012 KB |
testcase_20 | AC | 133 ms
50,836 KB |
testcase_21 | AC | 94 ms
47,856 KB |
testcase_22 | AC | 107 ms
48,632 KB |
testcase_23 | AC | 129 ms
49,220 KB |
testcase_24 | AC | 141 ms
52,268 KB |
testcase_25 | AC | 126 ms
48,520 KB |
testcase_26 | AC | 124 ms
49,084 KB |
testcase_27 | AC | 93 ms
44,360 KB |
testcase_28 | AC | 139 ms
51,976 KB |
testcase_29 | AC | 87 ms
43,444 KB |
testcase_30 | AC | 140 ms
52,128 KB |
testcase_31 | AC | 117 ms
48,464 KB |
testcase_32 | AC | 153 ms
52,076 KB |
testcase_33 | AC | 130 ms
48,944 KB |
testcase_34 | AC | 143 ms
49,416 KB |
testcase_35 | AC | 132 ms
48,924 KB |
testcase_36 | AC | 92 ms
43,816 KB |
testcase_37 | AC | 138 ms
51,964 KB |
ソースコード
import * as fs from 'fs' // import * as readline from 'readline' // const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) // const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve)) // // Don't forget `rl.close()`. const INT = Math.floor declare global { interface Array<T> { last(): T | undefined isEmpty(): boolean } } Array.prototype.last = function () { return this.length === 0 ? undefined : this[this.length - 1] } Array.prototype.isEmpty = function () { return this.length === 0 } const bigIntMax = (...args: bigint[]) => args.reduce((m, e) => (e > m ? e : m)) const bigIntMin = (...args: bigint[]) => args.reduce((m, e) => (e < m ? e : m)) const bigIntAbs = (arg: bigint) => (arg < 0 ? -arg : arg) declare const stdin: number function read_stdin() { return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8') } class Input { readonly inputs: string[] private index = 0 constructor(str?: string) { this.inputs = (str ? str : read_stdin()).split(/\s+/) } number() { return Number(this.inputs[this.index++]) } numbers(n: number) { return this.inputs.slice(this.index, (this.index += n)).map(Number) } bigint() { return BigInt(this.inputs[this.index++]) } bigints(n: number) { return this.inputs.slice(this.index, (this.index += n)).map(BigInt) } word() { return this.inputs[this.index++] } words(n: number) { return this.inputs.slice(this.index, (this.index += n)) } } function array<T>(len: number, init: T): T[] { return Array(len).fill(init) } function array2<T>(h: number, w: number, init: T): T[][] { return array(h, 0).map(() => array(w, init)) } function Mods(M: number, MAX_N = 0) { function mul(...A: number[]) { return A.reduce((r, a) => { const t = r * a return t < 2 ** 53 ? t % M : ((((r >> 16) * a) % M) * 65536 + (r & 65535) * a) % M }) } function pow(x: number, n: number) { let r = 1 for (; n; x = mul(x, x), n >>= 1) { if (n & 1) r = mul(r, x) } return r } const fac: number[] = Array(MAX_N + 1) const fac_inv: number[] = Array(MAX_N + 1) fac[0] = 1 fac_inv[0] = 1 for (let i = 1; i <= MAX_N; i++) { fac[i] = mul(fac[i - 1], i) fac_inv[i] = mul(fac_inv[i - 1], pow(i, M - 2)) } function nCr(n: number, r: number) { return mul(fac[n], fac_inv[r], fac_inv[n - r]) } function nPr(n: number, r: number) { return mul(fac[n], fac_inv[n - r]) } return { mul, pow, nCr, nPr } } function main() { const input = new Input() const M = 10 ** 9 + 7 const mod = Mods(10 ** 9 + 7) const N = input.word() const pows = array(N.length, 1) for (let i = 1; i < N.length; i++) { pows[i] = mod.mul(pows[i - 1], 45) } let sum = 0 let tight_mul = 1 for (let i = 0; i < N.length; i++) { const digit = Number(N[i]) if (tight_mul && digit > 1) { sum += mod.mul(tight_mul, (digit * (digit - 1)) / 2, pows[N.length - i - 1]) sum %= M } if (i < N.length - 1) { sum += pows[N.length - i - 1] sum %= M } tight_mul = mod.mul(tight_mul, digit) } const r = (sum + tight_mul) % M console.log(r < 0 ? r + M : r) } main()