結果

問題 No.1208 anti primenumber game
ユーザー ks2mks2m
提出日時 2020-08-30 15:12:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,141 bytes
コンパイル時間 3,924 ms
コンパイル使用メモリ 76,988 KB
実行使用メモリ 93,196 KB
最終ジャッジ日時 2024-04-27 08:03:32
合計ジャッジ時間 14,788 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
50,364 KB
testcase_01 AC 46 ms
50,352 KB
testcase_02 AC 45 ms
50,344 KB
testcase_03 AC 47 ms
50,404 KB
testcase_04 AC 47 ms
50,004 KB
testcase_05 AC 47 ms
50,324 KB
testcase_06 AC 45 ms
50,364 KB
testcase_07 AC 46 ms
50,296 KB
testcase_08 AC 47 ms
50,432 KB
testcase_09 AC 45 ms
50,412 KB
testcase_10 AC 45 ms
50,348 KB
testcase_11 AC 45 ms
50,452 KB
testcase_12 AC 46 ms
50,332 KB
testcase_13 AC 44 ms
50,220 KB
testcase_14 AC 48 ms
50,340 KB
testcase_15 AC 247 ms
92,204 KB
testcase_16 AC 230 ms
91,816 KB
testcase_17 AC 221 ms
90,584 KB
testcase_18 AC 228 ms
91,068 KB
testcase_19 AC 224 ms
91,476 KB
testcase_20 AC 227 ms
90,728 KB
testcase_21 AC 224 ms
91,452 KB
testcase_22 AC 236 ms
91,364 KB
testcase_23 AC 231 ms
91,448 KB
testcase_24 AC 316 ms
92,436 KB
testcase_25 AC 331 ms
93,196 KB
testcase_26 AC 320 ms
91,268 KB
testcase_27 AC 318 ms
91,736 KB
testcase_28 AC 333 ms
91,772 KB
testcase_29 AC 309 ms
81,352 KB
testcase_30 AC 236 ms
91,300 KB
testcase_31 AC 224 ms
92,032 KB
testcase_32 AC 229 ms
92,212 KB
testcase_33 AC 230 ms
92,184 KB
testcase_34 AC 236 ms
92,448 KB
testcase_35 AC 227 ms
92,844 KB
testcase_36 AC 209 ms
79,656 KB
testcase_37 AC 224 ms
91,888 KB
testcase_38 AC 315 ms
90,116 KB
testcase_39 AC 303 ms
91,416 KB
testcase_40 AC 316 ms
92,388 KB
testcase_41 AC 245 ms
87,984 KB
testcase_42 AC 270 ms
86,516 KB
testcase_43 AC 257 ms
87,880 KB
testcase_44 AC 272 ms
87,740 KB
testcase_45 AC 255 ms
87,708 KB
testcase_46 AC 227 ms
89,640 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