結果

問題 No.1208 anti primenumber game
ユーザー 👑 jupirojupiro
提出日時 2020-10-20 10:50:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 2,573 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 145,712 KB
実行使用メモリ 170,500 KB
最終ジャッジ日時 2023-09-28 13:38:18
合計ジャッジ時間 11,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 230 ms
145,196 KB
testcase_16 AC 229 ms
145,268 KB
testcase_17 AC 229 ms
145,084 KB
testcase_18 AC 231 ms
145,268 KB
testcase_19 AC 229 ms
145,136 KB
testcase_20 AC 230 ms
145,216 KB
testcase_21 AC 265 ms
167,596 KB
testcase_22 AC 263 ms
167,928 KB
testcase_23 AC 244 ms
157,760 KB
testcase_24 AC 290 ms
170,348 KB
testcase_25 AC 292 ms
170,164 KB
testcase_26 AC 289 ms
170,500 KB
testcase_27 AC 291 ms
170,220 KB
testcase_28 AC 293 ms
170,392 KB
testcase_29 AC 291 ms
170,160 KB
testcase_30 AC 245 ms
145,132 KB
testcase_31 AC 246 ms
145,276 KB
testcase_32 AC 236 ms
145,940 KB
testcase_33 AC 252 ms
162,584 KB
testcase_34 AC 256 ms
170,288 KB
testcase_35 AC 254 ms
170,360 KB
testcase_36 AC 199 ms
133,920 KB
testcase_37 AC 255 ms
170,276 KB
testcase_38 AC 277 ms
162,716 KB
testcase_39 AC 275 ms
162,636 KB
testcase_40 AC 284 ms
169,360 KB
testcase_41 AC 241 ms
147,312 KB
testcase_42 AC 258 ms
165,804 KB
testcase_43 AC 256 ms
165,872 KB
testcase_44 AC 251 ms
158,936 KB
testcase_45 AC 250 ms
158,944 KB
testcase_46 AC 221 ms
141,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 1100000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<ll> en = { 1, 4, 6 };
	ll n, m; cin >> n >> m;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i];
	vector dp(n + 1, vector(4, vector<ll>(2)));
	vector done(n + 1, vector(4, vector<bool>(2)));
	auto solve = [&](auto&& f, int cur, int b, int t)->ll {
		if (cur == n) return 0;
		if (done[cur][b][t]) return dp[cur][b][t];
		if (t == 0) {
			ll res = -INF;
			if (b == 3) {
				for (int i = 0; i < b; i++) {
					if (a[cur] <= en[i]) continue;
					chmax(res, a[cur] - en[i] + f(f, cur, i, 1));
				}
				chmax(res, a[cur] + f(f, cur + 1, 3, 1) - m);
			}
			else {
				for (int i = 0; i < b; i++) {
					chmax(res, en[b] - en[i] + f(f, cur, i, 1));
				}
				chmax(res, en[b] + f(f, cur + 1, 3, 1) - m);
			}
			done[cur][b][t] = true;
			return dp[cur][b][t] = res;
		}
		else {
			ll res = INF;
			if (b == 3) {
				for (int i = 0; i < b; i++) {
					if (a[cur] <= en[i]) continue;
					chmin(res, -(a[cur] - en[i]) + f(f, cur, i, 0));
				}
				chmin(res, -a[cur] + f(f, cur + 1, 3, 0) + m);
			}
			else {
				for (int i = 0; i < b; i++) {
					chmin(res, -(en[b] - en[i]) + f(f, cur, i, 0));
				}
				chmin(res, -en[b] + f(f, cur + 1, 3, 0) + m);
			}
			done[cur][b][t] = true;
			return dp[cur][b][t] = res;
		}
	};
	//cout << solve(solve, 0, 3, 0) << endl;
	if (solve(solve, 0, 3, 0) > 0) cout << "First" << endl;
	else cout << "Second" << endl;
}
0