結果
問題 | No.1208 anti primenumber game |
ユーザー |
![]() |
提出日時 | 2020-08-30 15:12:43 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 660 ms / 2,000 ms |
コード長 | 1,141 bytes |
コンパイル時間 | 2,887 ms |
コンパイル使用メモリ | 77,656 KB |
実行使用メモリ | 90,720 KB |
最終ジャッジ日時 | 2024-11-15 08:41:13 |
合計ジャッジ時間 | 16,090 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
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; } } }