結果
問題 | No.1407 Kindness |
ユーザー | yagisumi |
提出日時 | 2021-04-02 01:30:10 |
言語 | TypeScript (5.7.2) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 3,320 bytes |
コンパイル時間 | 8,512 ms |
コンパイル使用メモリ | 229,384 KB |
実行使用メモリ | 49,760 KB |
最終ジャッジ日時 | 2024-12-31 16:37:24 |
合計ジャッジ時間 | 13,089 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
40,192 KB |
testcase_01 | AC | 75 ms
39,936 KB |
testcase_02 | AC | 70 ms
39,936 KB |
testcase_03 | AC | 71 ms
40,320 KB |
testcase_04 | AC | 70 ms
39,936 KB |
testcase_05 | AC | 70 ms
40,064 KB |
testcase_06 | AC | 70 ms
39,936 KB |
testcase_07 | AC | 70 ms
39,936 KB |
testcase_08 | AC | 69 ms
40,064 KB |
testcase_09 | AC | 73 ms
40,192 KB |
testcase_10 | AC | 71 ms
39,808 KB |
testcase_11 | AC | 70 ms
39,936 KB |
testcase_12 | AC | 91 ms
47,104 KB |
testcase_13 | AC | 82 ms
45,184 KB |
testcase_14 | AC | 84 ms
45,412 KB |
testcase_15 | AC | 94 ms
47,104 KB |
testcase_16 | AC | 103 ms
45,884 KB |
testcase_17 | AC | 87 ms
45,616 KB |
testcase_18 | AC | 87 ms
45,584 KB |
testcase_19 | AC | 90 ms
46,848 KB |
testcase_20 | AC | 95 ms
46,116 KB |
testcase_21 | AC | 80 ms
44,800 KB |
testcase_22 | AC | 78 ms
45,056 KB |
testcase_23 | AC | 90 ms
45,960 KB |
testcase_24 | AC | 91 ms
47,104 KB |
testcase_25 | AC | 87 ms
45,584 KB |
testcase_26 | AC | 87 ms
45,716 KB |
testcase_27 | AC | 83 ms
45,056 KB |
testcase_28 | AC | 95 ms
46,848 KB |
testcase_29 | AC | 72 ms
40,832 KB |
testcase_30 | AC | 91 ms
47,104 KB |
testcase_31 | AC | 81 ms
45,440 KB |
testcase_32 | AC | 121 ms
49,760 KB |
testcase_33 | AC | 106 ms
46,312 KB |
testcase_34 | AC | 114 ms
46,840 KB |
testcase_35 | AC | 99 ms
46,464 KB |
testcase_36 | AC | 79 ms
44,928 KB |
testcase_37 | AC | 91 ms
47,488 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, 1) for (let i = 1; i <= N.length; i++) { pows[i] = mod.mul(pows[i - 1], 45) } const inv = mod.pow(44, M - 2) let sum = 0 if (N.length > 1) { sum = mod.mul(pows[N.length] - 45, inv) } 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 } tight_mul = mod.mul(tight_mul, digit) if (digit === 0) break } const r = (sum + tight_mul) % M console.log(r < 0 ? r + M : r) } main()