結果
問題 | No.603 hel__world (2) |
ユーザー | 37zigen |
提出日時 | 2017-12-21 06:49:42 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,506 bytes |
コンパイル時間 | 3,559 ms |
コンパイル使用メモリ | 82,456 KB |
実行使用メモリ | 120,524 KB |
最終ジャッジ日時 | 2024-05-10 02:09:10 |
合計ジャッジ時間 | 16,052 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 195 ms
65,284 KB |
testcase_01 | AC | 192 ms
65,288 KB |
testcase_02 | AC | 198 ms
65,196 KB |
testcase_03 | AC | 193 ms
65,216 KB |
testcase_04 | AC | 190 ms
65,160 KB |
testcase_05 | AC | 191 ms
65,328 KB |
testcase_06 | AC | 191 ms
65,108 KB |
testcase_07 | AC | 191 ms
65,324 KB |
testcase_08 | AC | 190 ms
65,100 KB |
testcase_09 | AC | 192 ms
65,132 KB |
testcase_10 | AC | 191 ms
64,992 KB |
testcase_11 | AC | 518 ms
89,228 KB |
testcase_12 | AC | 465 ms
82,844 KB |
testcase_13 | AC | 499 ms
88,456 KB |
testcase_14 | AC | 195 ms
65,148 KB |
testcase_15 | AC | 198 ms
65,516 KB |
testcase_16 | AC | 198 ms
65,316 KB |
testcase_17 | AC | 193 ms
65,228 KB |
testcase_18 | AC | 198 ms
65,392 KB |
testcase_19 | AC | 193 ms
65,400 KB |
testcase_20 | AC | 369 ms
77,212 KB |
testcase_21 | AC | 365 ms
77,160 KB |
testcase_22 | AC | 196 ms
65,212 KB |
testcase_23 | AC | 194 ms
65,352 KB |
testcase_24 | AC | 193 ms
65,208 KB |
testcase_25 | AC | 992 ms
98,904 KB |
testcase_26 | AC | 1,005 ms
99,016 KB |
testcase_27 | AC | 1,122 ms
98,988 KB |
testcase_28 | AC | 1,073 ms
120,524 KB |
testcase_29 | AC | 364 ms
76,864 KB |
testcase_30 | AC | 346 ms
77,136 KB |
testcase_31 | AC | 193 ms
65,248 KB |
testcase_32 | RE | - |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; class Main { class State implements Comparable<State> { long a, b; public State(long a_, long b_) { a = a_; b = b_; } void inc() { long x = a - 1; long y = a - b; a = a + 1; b = a - y; } @Override public int compareTo(State o) { return -Long.compare(a * o.b, o.a * b); } } final long MOD = 1_000_000 + 3; long[] fac = new long[(int) MOD]; long[] invfac = new long[(int) MOD]; long[] inv = new long[(int) MOD]; { fac[0] = invfac[0] = fac[1] = invfac[1] = inv[1] = 1; for (int i = 2; i < MOD; ++i) { fac[i] = i * fac[i - 1] % MOD; inv[i] = MOD - inv[(int) MOD % i] * (MOD / i) % MOD; invfac[i] = inv[i] * invfac[i - 1] % MOD; } } long comb(long n, long k) { long ret = 1; while (n > 0 || k > 0) { ret = ret * comb((int) (n % MOD), (int) (k % MOD)) % MOD; n /= MOD; k /= MOD; } return ret; } long comb(int n, int k) { return fac[n] * invfac[k] % MOD * invfac[n - k] % MOD; } long f(ArrayList<Long> list, long s) { long res = s; long all = 0; long ret = 1; for (long v : list) { all += v; } if (all == s) return 1; if (all > s) return 0; if (list.size() == 0) return 1; PriorityQueue<State> pq = new PriorityQueue<>(); for (int i = 0; i < list.size(); ++i) { long y = (list.get(i) * s / all) - 1; y = Math.max(y, list.get(i)); ret = ret * comb(y, list.get(i)) % MOD; res -= y; pq.add(new State(y + 1, y + 1 - list.get(i))); } while (res > 0) { State state = pq.poll(); ret = ret * (state.a % MOD) % MOD * inv[(int) (state.b % MOD)] % MOD; --res; state.inc(); pq.add(state); } return ret; } void run() { Scanner sc = new Scanner(System.in); long[] s = new long[26]; for (int i = 0; i < 26; ++i) { s[i] = sc.nextLong(); } String T = sc.next(); ArrayList<Long>[] list = new ArrayList[26]; for (int i = 0; i < list.length; ++i) list[i] = new ArrayList(); for (int i = 0; i < T.length(); ++i) { long c = 1; while (i + 1 < T.length() && T.charAt(i) == T.charAt(i + 1)) { ++c; ++i; } list[T.charAt(i) - 'a'].add(c); } long ret = 1; for (int i = 0; i < 26; ++i) { ret = ret * f(list[i], s[i]) % MOD; } System.out.println(ret); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } public static void main(String[] args) { new Main().run(); } }