結果

問題 No.1208 anti primenumber game
ユーザー ks2mks2m
提出日時 2020-08-30 15:12:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 1,141 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 73,976 KB
実行使用メモリ 93,548 KB
最終ジャッジ日時 2023-08-09 13:03:08
合計ジャッジ時間 13,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,268 KB
testcase_01 AC 42 ms
49,232 KB
testcase_02 AC 41 ms
49,432 KB
testcase_03 AC 43 ms
49,444 KB
testcase_04 AC 43 ms
49,288 KB
testcase_05 AC 43 ms
49,476 KB
testcase_06 AC 42 ms
49,308 KB
testcase_07 AC 42 ms
49,432 KB
testcase_08 AC 42 ms
49,468 KB
testcase_09 AC 43 ms
49,244 KB
testcase_10 AC 42 ms
49,424 KB
testcase_11 AC 42 ms
49,428 KB
testcase_12 AC 42 ms
49,728 KB
testcase_13 AC 42 ms
49,240 KB
testcase_14 AC 41 ms
49,432 KB
testcase_15 AC 244 ms
87,520 KB
testcase_16 AC 237 ms
88,884 KB
testcase_17 AC 244 ms
87,684 KB
testcase_18 AC 236 ms
87,164 KB
testcase_19 AC 231 ms
87,768 KB
testcase_20 AC 245 ms
84,964 KB
testcase_21 AC 249 ms
88,096 KB
testcase_22 AC 247 ms
88,344 KB
testcase_23 AC 248 ms
87,448 KB
testcase_24 AC 341 ms
92,960 KB
testcase_25 AC 336 ms
92,756 KB
testcase_26 AC 326 ms
92,864 KB
testcase_27 AC 328 ms
92,364 KB
testcase_28 AC 327 ms
91,752 KB
testcase_29 AC 328 ms
93,548 KB
testcase_30 AC 242 ms
88,096 KB
testcase_31 AC 236 ms
88,416 KB
testcase_32 AC 238 ms
86,488 KB
testcase_33 AC 237 ms
88,892 KB
testcase_34 AC 246 ms
88,388 KB
testcase_35 AC 240 ms
88,460 KB
testcase_36 AC 206 ms
79,892 KB
testcase_37 AC 235 ms
87,352 KB
testcase_38 AC 317 ms
91,784 KB
testcase_39 AC 333 ms
91,192 KB
testcase_40 AC 336 ms
90,484 KB
testcase_41 AC 248 ms
90,644 KB
testcase_42 AC 264 ms
90,340 KB
testcase_43 AC 252 ms
90,216 KB
testcase_44 AC 254 ms
90,748 KB
testcase_45 AC 257 ms
89,568 KB
testcase_46 AC 223 ms
83,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int n;
	static long m;
	static long[] a;
	static long[][] dp;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		m = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		dp = new long[2][n + 1];
		Arrays.fill(dp[0], Long.MIN_VALUE);
		Arrays.fill(dp[1], Long.MIN_VALUE);
		dp[0][n] = 0;
		dp[1][n] = 0;
		if (dfs(0, 0) > 0) {
			System.out.println("First");
		} else {
			System.out.println("Second");
		}
	}

	static long dfs(int o, int x) {
		if (dp[o][x] != Long.MIN_VALUE) {
			return dp[o][x];
		}
		long res = dfs(0, x + 1);
		if (o == 1) {
			return dp[o][x] = 1 - m - res;
		} else {
			long val = a[x] - m - res;
			if (a[x] > 1) {
				long val2 = a[x] - 1 - (1 - m) + res;
				val = Math.max(val, val2);
			}
			return dp[o][x] = val;
		}
	}
}
0