結果
問題 | No.2846 Birthday Cake |
ユーザー | uwi |
提出日時 | 2024-08-29 13:52:37 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,924 bytes |
コンパイル時間 | 5,538 ms |
コンパイル使用メモリ | 88,276 KB |
実行使用メモリ | 87,736 KB |
最終ジャッジ日時 | 2024-08-29 13:53:24 |
合計ジャッジ時間 | 10,491 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 163 ms
54,004 KB |
testcase_01 | AC | 142 ms
54,052 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 129 ms
53,224 KB |
testcase_04 | AC | 140 ms
54,164 KB |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 1,686 ms
81,296 KB |
testcase_13 | AC | 1,880 ms
82,416 KB |
testcase_14 | AC | 208 ms
56,872 KB |
testcase_15 | AC | 533 ms
69,908 KB |
testcase_16 | AC | 520 ms
69,240 KB |
testcase_17 | AC | 1,885 ms
80,392 KB |
testcase_18 | TLE | - |
testcase_19 | AC | 162 ms
53,640 KB |
testcase_20 | AC | 215 ms
56,896 KB |
testcase_21 | AC | 134 ms
54,260 KB |
testcase_22 | AC | 406 ms
68,360 KB |
testcase_23 | AC | 359 ms
65,560 KB |
testcase_24 | AC | 1,950 ms
84,180 KB |
testcase_25 | AC | 129 ms
53,804 KB |
testcase_26 | AC | 317 ms
61,144 KB |
testcase_27 | AC | 578 ms
69,956 KB |
testcase_28 | AC | 129 ms
53,788 KB |
testcase_29 | AC | 453 ms
69,552 KB |
testcase_30 | AC | 123 ms
52,928 KB |
testcase_31 | AC | 259 ms
59,424 KB |
testcase_32 | AC | 886 ms
70,916 KB |
testcase_33 | AC | 1,843 ms
79,216 KB |
testcase_34 | AC | 524 ms
69,300 KB |
testcase_35 | WA | - |
testcase_36 | AC | 1,871 ms
80,152 KB |
ソースコード
package no2xxx; import java.io.PrintWriter; import java.util.*; public class No2846 { static Scanner in; static PrintWriter out; static String INPUT = ""; static void solve() { int K = ni(), n = ni(); Map<Long, long[]> dp = new HashMap<>(); Map<Long, Long> nums = new HashMap<>(); dp.put(1L, new long[]{0, 1}); nums.put(1L, 1L); for(int i = 0;i < K;i++){ Map<Long, long[]> ndp = new HashMap<>(); Map<Long, Long> nnums = new HashMap<>(); for(long key : dp.keySet()){ long[] f = dp.get(key); for(int j = n;j >= 1;j--) { if(j == 23 || j == 19 || j == 17 || j == 13)continue; long[] nf = add(f, new long[]{1, j}); if (nf[0] > nf[1]) break; ndp.put(h(nf), nf); nnums.merge(h(nf), nums.get(key), Long::sum); } } dp = ndp; nums = nnums; } long ans = nums.getOrDefault(h(new long[]{1, 1}), 0L); if(n == K && (n == 13 || n == 17 || n == 19 || n == 23))ans++; out.println(ans); } static long h(long[] a) { long ret = 0; for(long v : a)ret = ret * 1000000009 + v; return ret; } public static long[] reduce(long[] f) { if(f[1] == 0) { // n/0 f[0] = 1; }else if(f[0] == 0) { // 0/n f[1] = 1; }else { if(f[1] < 0) { // -a/-b ->a/b f[0] = -f[0]; f[1] = -f[1]; } long a = Math.abs(f[0]), b = f[1]; while (b > 0) { long c = a; a = b; b = c % b; } f[0] /= a; f[1] /= a; } return f; } public static long[] add(long[] a, long[] b){ return reduce(new long[]{a[0]*b[1]+a[1]*b[0], a[1]*b[1]}); } public static long[] sub(long[] a, long[] b){ return reduce(new long[]{a[0]*b[1]-a[1]*b[0], a[1]*b[1]}); } public static long[] mul(long[] a, long[] b){ return reduce(new long[]{a[0]*b[0], a[1]*b[1]}); } public static long[] div(long[] a, long[] b){ return reduce(new long[]{a[0]*b[1], a[1]*b[0]}); } public static int compare(long[] a, long[] b){return Long.signum(a[0] * b[1] - a[1] * b[0]);} public static long[] min(long[] a, long[] b){ return compare(a, b) <= 0 ? a : b; } public static long[] max(long[] a, long[] b){ return compare(a, b) >= 0 ? a : b; } public static int lowerBound(long[][] es, int p, long[] r) { int low = -1, high = p; while(high-low > 1){ int h = high+low>>>1; if(Long.compare(r[0]*es[h][1], r[1]*es[h][0]) <= 0){ high = h; }else{ low = h; } } return high; } public static Comparator<long[]> comp = (a, b) -> Long.signum(a[0]*b[1]-a[1]*b[0]); public static void main(String[] args) throws Exception { in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT); out = new PrintWriter(System.out); solve(); out.flush(); } static int ni() { return Integer.parseInt(in.next()); } static long nl() { return Long.parseLong(in.next()); } static double nd() { return Double.parseDouble(in.next()); } static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }