結果

問題 No.1208 anti primenumber game
ユーザー yuma220284yuma220284
提出日時 2020-08-30 13:57:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 166,704 KB
実行使用メモリ 34,600 KB
最終ジャッジ日時 2024-04-27 07:12:56
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 55 ms
24,932 KB
testcase_16 AC 54 ms
25,028 KB
testcase_17 AC 53 ms
25,140 KB
testcase_18 AC 54 ms
25,096 KB
testcase_19 AC 54 ms
25,092 KB
testcase_20 AC 54 ms
25,104 KB
testcase_21 AC 65 ms
33,416 KB
testcase_22 AC 65 ms
33,372 KB
testcase_23 AC 62 ms
29,732 KB
testcase_24 AC 139 ms
34,344 KB
testcase_25 AC 139 ms
34,372 KB
testcase_26 AC 130 ms
34,276 KB
testcase_27 AC 132 ms
34,416 KB
testcase_28 AC 133 ms
34,444 KB
testcase_29 AC 129 ms
34,316 KB
testcase_30 AC 54 ms
25,068 KB
testcase_31 AC 55 ms
25,024 KB
testcase_32 AC 52 ms
25,376 KB
testcase_33 AC 62 ms
31,584 KB
testcase_34 AC 64 ms
34,424 KB
testcase_35 AC 64 ms
34,600 KB
testcase_36 AC 51 ms
27,628 KB
testcase_37 AC 66 ms
34,448 KB
testcase_38 AC 113 ms
31,432 KB
testcase_39 AC 113 ms
31,576 KB
testcase_40 AC 129 ms
34,188 KB
testcase_41 AC 62 ms
25,916 KB
testcase_42 AC 70 ms
32,584 KB
testcase_43 AC 68 ms
32,692 KB
testcase_44 AC 67 ms
30,116 KB
testcase_45 AC 67 ms
30,140 KB
testcase_46 AC 56 ms
26,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

long long INF = 1000000000000000000;

long long N, M;
vector<long long> A;
vector<vector<long long> > DP;

long long DFS(long long X, int Y) {
	if (X == N) return 0;
	if (DP[X][Y] != -INF) return DP[X][Y];
	if (Y == 0) {
		if (A[X + 1] == 1) return DP[X][Y] = -DFS(X + 1, 0) + 1 - M;
		else return DP[X][Y] = -DFS(X + 1, 1) + 1 - M;
	}
	else {
		DP[X][Y] = max(DP[X][Y], -DFS(X, 0) + A[X] - 1);
		if (A[X + 1] == 1) DP[X][Y] = max(DP[X][Y], -DFS(X + 1, 0) + A[X] - M);
		else DP[X][Y] = max(DP[X][Y], -DFS(X + 1, 1) + A[X] - M);
		return DP[X][Y];
	}
}

int main() {
	cin >> N >> M;
	A.resize(N + 1);
	for (int i = 0; i < N; i++) cin >> A[i];
	A[N] = 1;
	DP.assign(N, vector<long long>(2, -INF));
	if (A[0] == 1) {
		DFS(0, 0);
		cout << (DP[0][0] > 0 ? "First" : "Second") << endl;
	}
	else {
		DFS(0, 1);
		cout << (DP[0][1] > 0 ? "First" : "Second") << endl;
	}
}
0