結果

問題 No.2846 Birthday Cake
ユーザー uwiuwi
提出日時 2024-08-29 13:59:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,026 bytes
コンパイル時間 4,292 ms
コンパイル使用メモリ 85,312 KB
実行使用メモリ 73,872 KB
最終ジャッジ日時 2024-08-29 14:00:14
合計ジャッジ時間 30,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
53,300 KB
testcase_01 AC 134 ms
53,368 KB
testcase_02 AC 1,224 ms
71,388 KB
testcase_03 AC 127 ms
53,516 KB
testcase_04 AC 127 ms
53,368 KB
testcase_05 AC 1,255 ms
72,268 KB
testcase_06 WA -
testcase_07 AC 1,348 ms
73,624 KB
testcase_08 WA -
testcase_09 AC 1,402 ms
73,776 KB
testcase_10 AC 1,395 ms
73,872 KB
testcase_11 AC 1,407 ms
73,316 KB
testcase_12 AC 1,037 ms
71,316 KB
testcase_13 AC 1,193 ms
72,760 KB
testcase_14 AC 195 ms
56,428 KB
testcase_15 AC 393 ms
63,196 KB
testcase_16 AC 431 ms
64,644 KB
testcase_17 AC 1,130 ms
72,276 KB
testcase_18 AC 1,489 ms
73,724 KB
testcase_19 AC 142 ms
53,388 KB
testcase_20 AC 184 ms
56,528 KB
testcase_21 AC 127 ms
53,548 KB
testcase_22 AC 353 ms
62,488 KB
testcase_23 AC 308 ms
61,040 KB
testcase_24 AC 1,137 ms
71,476 KB
testcase_25 AC 137 ms
53,364 KB
testcase_26 AC 286 ms
59,188 KB
testcase_27 AC 422 ms
64,516 KB
testcase_28 AC 128 ms
53,656 KB
testcase_29 AC 435 ms
65,372 KB
testcase_30 AC 127 ms
53,336 KB
testcase_31 AC 204 ms
56,748 KB
testcase_32 AC 658 ms
68,884 KB
testcase_33 AC 1,142 ms
71,952 KB
testcase_34 AC 434 ms
65,068 KB
testcase_35 WA -
testcase_36 AC 1,148 ms
72,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no2xxx;
import java.io.PrintWriter;
import java.util.*;

public class No2846 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";

	static class Datum
	{
		long[] f;
		long v;

		public Datum(long[] f, long v) {
			this.f = f;
			this.v = v;
		}
	}
	
	static void solve()
	{
		int K = ni(), n = ni();
		Map<Long, Datum> dp = new HashMap<>();
		dp.put(1L, new Datum(new long[]{0, 1}, 1L));

		for(int i = 0;i < K;i++){
			Map<Long, Datum> ndp = new HashMap<>();
			for(long key : dp.keySet()){
				Datum d = dp.get(key);
				for(int j = n;j >= 1;j--) {
					if(j == 23 || j == 19 || j == 17 || j == 13)continue;
					long[] nf = add(d.f, new long[]{1, j});
					if (nf[0] > nf[1]) break;
					if (ndp.containsKey(h(nf))) {
						ndp.get(h(nf)).v += d.v;
					}else{
						Datum add = new Datum(nf, d.v);
						ndp.put(h(nf), add);
					}
				}
			}
			dp = ndp;
		}
		Datum d = dp.get(h(new long[]{1, 1}));
		long ans = d != null ? d.v : 0;
		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)); }
}
0