結果
問題 | No.1685 One by One |
ユーザー | hitonanode |
提出日時 | 2021-08-14 11:49:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,106 ms / 3,000 ms |
コード長 | 3,458 bytes |
コンパイル時間 | 3,058 ms |
コンパイル使用メモリ | 76,972 KB |
実行使用メモリ | 56,092 KB |
最終ジャッジ日時 | 2024-06-29 19:29:18 |
合計ジャッジ時間 | 26,711 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
52,916 KB |
testcase_01 | AC | 130 ms
53,700 KB |
testcase_02 | AC | 141 ms
53,728 KB |
testcase_03 | AC | 491 ms
55,972 KB |
testcase_04 | AC | 296 ms
55,568 KB |
testcase_05 | AC | 583 ms
55,300 KB |
testcase_06 | AC | 536 ms
55,712 KB |
testcase_07 | AC | 521 ms
55,392 KB |
testcase_08 | AC | 176 ms
54,780 KB |
testcase_09 | AC | 211 ms
55,124 KB |
testcase_10 | AC | 963 ms
55,576 KB |
testcase_11 | AC | 212 ms
54,120 KB |
testcase_12 | AC | 179 ms
54,644 KB |
testcase_13 | AC | 538 ms
55,056 KB |
testcase_14 | AC | 416 ms
56,092 KB |
testcase_15 | AC | 741 ms
55,416 KB |
testcase_16 | AC | 248 ms
54,900 KB |
testcase_17 | AC | 183 ms
55,224 KB |
testcase_18 | AC | 213 ms
54,828 KB |
testcase_19 | AC | 129 ms
52,616 KB |
testcase_20 | AC | 390 ms
54,616 KB |
testcase_21 | AC | 234 ms
54,500 KB |
testcase_22 | AC | 435 ms
54,316 KB |
testcase_23 | AC | 334 ms
54,440 KB |
testcase_24 | AC | 971 ms
55,896 KB |
testcase_25 | AC | 1,012 ms
55,280 KB |
testcase_26 | AC | 1,051 ms
55,884 KB |
testcase_27 | AC | 853 ms
55,100 KB |
testcase_28 | AC | 1,106 ms
55,652 KB |
testcase_29 | AC | 892 ms
54,980 KB |
testcase_30 | AC | 1,072 ms
55,508 KB |
testcase_31 | AC | 866 ms
55,276 KB |
testcase_32 | AC | 878 ms
55,128 KB |
testcase_33 | AC | 882 ms
55,000 KB |
testcase_34 | AC | 132 ms
54,032 KB |
testcase_35 | AC | 134 ms
53,768 KB |
testcase_36 | AC | 132 ms
53,996 KB |
testcase_37 | AC | 132 ms
53,940 KB |
testcase_38 | AC | 406 ms
55,568 KB |
testcase_39 | AC | 397 ms
55,044 KB |
testcase_40 | AC | 203 ms
55,376 KB |
testcase_41 | AC | 209 ms
54,620 KB |
testcase_42 | AC | 127 ms
53,760 KB |
testcase_43 | AC | 129 ms
53,980 KB |
testcase_44 | AC | 128 ms
53,956 KB |
testcase_45 | AC | 127 ms
53,916 KB |
testcase_46 | AC | 523 ms
56,012 KB |
testcase_47 | AC | 435 ms
55,436 KB |
testcase_48 | AC | 508 ms
56,016 KB |
testcase_49 | AC | 435 ms
55,516 KB |
ソースコード
import java.util.*; public class Main { static int pow(long x, int k, int md) { long ret = 1; while (k > 0) { if ((k & 1) == 1) { ret = ret * x % md; } x = x * x % md; k >>= 1; } return (int)ret; } public class Acl_fac { long facs[]; long facinvs[]; int md; public Acl_fac(int N, int md) { this.facs = new long[N + 1]; this.facinvs = new long[N + 1]; this.md = md; this.facs[0] = this.facinvs[0] = 1; for (int i = 1; i <= N; i++) this.facs[i] = this.facs[i - 1] * i % md; this.facinvs[N] = pow(this.facs[N], md - 2, md); for (int i = N; i > 0; i--) this.facinvs[i - 1] = this.facinvs[i] * i % md; } long ncr(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; return this.facs[n] * this.facinvs[r] % this.md * this.facinvs[n - r] % this.md; } } final static int md = 1000000007; public long run() { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); Acl_fac fac = new Acl_fac(N + M, md); final long precalc[] = new long[M + 1]; long ret = 0; for (int nnonzero = 0; nnonzero <= N; nnonzero++) { if (nnonzero == 0) precalc[0] = 1; for (int m = 0; m <= M; m++) { if (nnonzero + m - 1 >= 0) precalc[m] = fac.ncr(nnonzero + m - 1, nnonzero - 1); if (m >= 2) { precalc[m] += precalc[m - 2]; if (precalc[m] >= md) precalc[m] -= md; } } if (N % 2 == 0) { int half = (N - 1) / 2; if (nnonzero > half * 2) continue; long coeff = 0; for (int npos = 0; npos <= half; npos++) { int nneg = nnonzero - npos; if (nneg < 0 || nneg > half) continue; coeff += fac.ncr(N - 1, npos) * fac.ncr(N - 1 - npos, nneg); coeff %= md; } long tmp = 0; for (int b0 = 0; b0 <= M; b0++) { if (M - nnonzero - b0 < 0) continue; tmp += precalc[M - nnonzero - b0] * (b0 == 0 ? 1 : 2); tmp %= md; } ret += tmp * coeff; ret %= md; } else { long sum = 0; for (int npos = 0; npos <= N / 2; npos++) { int nneg = nnonzero - npos; if (nneg < 0 || nneg > N / 2) continue; long coeff = 0; if (M - nnonzero >= 0) coeff += precalc[M - nnonzero]; int m = M - npos - (N - nneg); if (m >= 0) coeff += precalc[m] * 2; m = M - (N - nnonzero) - (npos > nneg ? npos : nneg) * 2; if (m >= 0) coeff += md - precalc[m]; sum += fac.ncr(nnonzero, npos) * coeff; sum %= md; } ret += fac.ncr(N, nnonzero) * sum; ret %= md; } } return ret; } public static void main(String[] args) { long ret = new Main().run(); System.out.println(ret); } }