結果
問題 | No.1629 Sorting Integers (SUM of M) |
ユーザー |
|
提出日時 | 2021-07-30 21:00:43 |
言語 | Kuin (KuinC++ v.2021.9.17) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 2,946 ms |
コンパイル使用メモリ | 149,820 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-16 12:41:11 |
合計ジャッジ時間 | 3,808 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
func main()const mod: int :: 1000000007var n: int :: cui@inputInt()var a: []int :: #[10]intfor i(1, 9)do a[i] :: cui@inputInt()end forvar ans: @ModInt :: (#@ModInt).init(0, mod)for(1, n)do ans.mul(10)do ans.add(1)end forvar comb: @Comb :: (#@Comb).init(n, mod)var ans2: @ModInt :: (#@ModInt).init(0, mod)for i(1, 9)if(a[i] = 0)skip iend ifvar tmp: @ModInt :: (#@ModInt).init(1, mod)var total: int :: n - 1for j(1, 9)if(i = j)do tmp.mul(comb.comb(total, a[j] - 1))do total :- a[j] - 1elsedo tmp.mul(comb.comb(total, a[j]))do total :- a[j]end ifend fordo tmp.mul(i)do ans2.add(tmp.val)end fordo ans.mul(ans2.val)do cui@print("\{ans}\n")end funcclass Comb()var mod: intvar fact: []intvar inv: []int+func init(n: int, mod: int): Combdo me.mod :: moddo me.fact :: #[n + 1]intdo me.inv :: #[n + 1]intdo me.fact[0] :: 1for i(1, n)do me.fact[i] :: me.fact[i - 1] * i % modend fordo me.inv[n] :: math@modPow(me.fact[n], mod - 2, mod)for i(n, 1, -1)do me.inv[i - 1] :: me.inv[i] * i % modend forret meend func+func comb(n: int, r: int): intret me.fact[n] * me.inv[n - r] % me.mod * me.inv[r] % me.modend funcend class; val, mod, a, b: 0 to 2 ^ 31.class ModInt()+var val: intvar mod: int+*func toStr(): []charret "\{me.val}"end func+func init(val: int, mod: int): ModIntdo me.val :: val % moddo me.mod :: modret meend func+func add(a: int): ModIntdo me.val :+ aif(me.val >= me.mod)do me.val :- me.modend ifret meend func+func sub(a: int): ModIntif(me.val < a)do me.val :+ me.modend ifdo me.val :- aret meend func+func mul(a: int): ModIntdo me.val :: me.val * a % me.modret meend func+func div(a: int): ModIntdo me.val :: me.val * me.modPow(a, me.mod - 2) % me.modret meend func+func pow(a: int): ModIntdo me.val :: me.modPow(me.val, a)ret meend funcfunc modPow(a: int, b: int): intif(b = 0)ret 1end ifvar res: int :: me.modPow(a, b / 2)do res :: res * res % me.modif(b % 2 = 1)do res :: res * a % me.modend ifret resend funcend class