結果
問題 | No.603 hel__world (2) |
ユーザー | zimpha |
提出日時 | 2017-12-03 03:15:26 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,629 bytes |
コンパイル時間 | 386 ms |
コンパイル使用メモリ | 7,168 KB |
実行使用メモリ | 71,296 KB |
最終ジャッジ日時 | 2024-05-06 04:48:21 |
合計ジャッジ時間 | 25,476 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 616 ms
69,760 KB |
testcase_01 | AC | 618 ms
69,760 KB |
testcase_02 | WA | - |
testcase_03 | AC | 629 ms
69,888 KB |
testcase_04 | AC | 615 ms
69,760 KB |
testcase_05 | WA | - |
testcase_06 | AC | 622 ms
69,760 KB |
testcase_07 | RE | - |
testcase_08 | AC | 611 ms
69,760 KB |
testcase_09 | AC | 619 ms
69,760 KB |
testcase_10 | WA | - |
testcase_11 | AC | 892 ms
70,912 KB |
testcase_12 | WA | - |
testcase_13 | AC | 921 ms
70,912 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 780 ms
70,912 KB |
testcase_30 | RE | - |
testcase_31 | AC | 626 ms
69,888 KB |
testcase_32 | AC | 808 ms
70,784 KB |
ソースコード
mod = 10 ** 6 + 3 denom = 10 * 40 fac = [1] * mod inv = [1] * mod for i in xrange(2, mod): fac[i] = i * fac[i - 1] % mod inv[i] = (mod - mod / i) * inv[mod % i] % mod def solve(): def binom(n, m): if n < m: return 0 if n == m or m == 0: return 1 nq, nr = divmod(n, mod) mq, mr = divmod(m, mod) if nr < mr: return 0 return fac[nr] * inv[fac[mr]] * inv[fac[nr - mr]] * binom(nq, mq) % mod counts = map(int, raw_input().split()) s = raw_input() n = len(s) lens = [] for i in xrange(26): lens.append({}) freqs = [0] * 26 last, cnt = -1, 0 for c in s: i = ord(c) - ord('a') if last == i: cnt += 1 else: if cnt: if cnt in lens[last]: lens[last][cnt] += 1 else: lens[last][cnt] = 1 cnt = 1 freqs[i] += 1 last = i if cnt in lens[last]: lens[last][cnt] += 1 else: lens[last][cnt] = 1 lens = [x.items() for x in lens] ans = 1 for i in xrange(26): if counts[i] < freqs[i]: return 0 if freqs[i] == 0 or counts[i] == freqs[i]: continue if len(lens[i]) == 1 and lens[i][0][1] == 1: ans = ans * binom(counts[i], lens[i][0][0]) % mod else: rest = counts[i] - freqs[i] ok = denom + 1 ng = n * denom + 1 exact = False while ng - ok > 1: mid = (ok + ng) >> 1 total = 0 for l, c in lens[i]: total += (l * denom) / (mid - denom) * c if total >= rest: ok = mid if total == rest: exact = True ng = mid else: ng = mid for l, c in lens[i]: k = (l * denom) / (ng - denom) if k: ans = ans * pow(binom(l + k, l) % mod, c, mod) rest -= k * c assert rest >= 0 if not exact: for l, c in lens[i]: k1 = (l * denom) / (ok - denom) k2 = (l * denom) / (ng - denom) if k1 > k2: assert k1 == k2 + 1 ans = ans * pow((k1 + l) * inv[k1 % mod] % mod, min(rest, c), mod) rest -= min(rest, c) if rest == 0: break return ans print solve()