結果
| 問題 | No.1208 anti primenumber game |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-20 10:50:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 327 ms / 2,000 ms |
| コード長 | 2,573 bytes |
| 記録 | |
| コンパイル時間 | 3,857 ms |
| コンパイル使用メモリ | 140,736 KB |
| 最終ジャッジ日時 | 2025-01-15 11:56:48 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
#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;
}