結果

問題 No.1208 anti primenumber game
ユーザー tomatoma
提出日時 2020-08-30 15:11:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,828 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 203,772 KB
実行使用メモリ 10,976 KB
最終ジャッジ日時 2023-08-09 13:02:15
合計ジャッジ時間 6,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 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,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 34 ms
10,812 KB
testcase_16 AC 33 ms
10,904 KB
testcase_17 AC 34 ms
10,764 KB
testcase_18 AC 34 ms
10,760 KB
testcase_19 AC 33 ms
10,968 KB
testcase_20 AC 34 ms
10,916 KB
testcase_21 AC 34 ms
10,808 KB
testcase_22 AC 34 ms
10,764 KB
testcase_23 AC 34 ms
10,920 KB
testcase_24 AC 104 ms
10,848 KB
testcase_25 AC 103 ms
10,884 KB
testcase_26 AC 98 ms
10,752 KB
testcase_27 AC 97 ms
10,920 KB
testcase_28 AC 97 ms
10,908 KB
testcase_29 AC 97 ms
10,852 KB
testcase_30 AC 34 ms
10,820 KB
testcase_31 AC 34 ms
10,976 KB
testcase_32 AC 33 ms
10,812 KB
testcase_33 AC 33 ms
10,856 KB
testcase_34 AC 33 ms
10,944 KB
testcase_35 AC 34 ms
10,896 KB
testcase_36 AC 27 ms
9,136 KB
testcase_37 AC 34 ms
10,856 KB
testcase_38 AC 78 ms
10,756 KB
testcase_39 AC 78 ms
10,760 KB
testcase_40 AC 95 ms
10,792 KB
testcase_41 AC 40 ms
10,920 KB
testcase_42 AC 40 ms
10,760 KB
testcase_43 AC 40 ms
10,768 KB
testcase_44 AC 40 ms
10,836 KB
testcase_45 AC 40 ms
10,836 KB
testcase_46 AC 31 ms
10,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
//using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

using Mat = array<array<ll, 2>, 2>;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];

    vector<Mat> dp(N + 1);
    for (auto& mat : dp)rep(i, 2)rep(j, 2)mat[i][j] = INFL;
    rep(i, 2)rep(j, 2)dp.back()[i][j] = 0;

    for (int land = N - 1; land >= 0; --land) {
        // 1つ残っている = false
        {
            // 先手 = true
            dp[land][false][true] = dp[land + 1][true][false] + 1 - M;
            // 後手 = false
            dp[land][false][false] = dp[land + 1][true][true] - (1 - M);
        }
        // 全て残っている = true
        {
            // 先手 = true
            dp[land][true][true] = max(
                A[land] > 1 ? dp[land][false][false] + A[land] - 1 : -INFL,   // 1つ残して取る
                dp[land + 1][true][false] + A[land] - M // 全部取る
            );
            // 後手 = false
            dp[land][true][false] = min(
                A[land] > 1 ? dp[land][false][true] - (A[land] - 1) : INFL, // 1つ残して取る
                dp[land + 1][true][true] - (A[land] - M) // 全部取る
            );
        }
    }

    auto value = dp.front()[true][true];
    cout << (value > 0 ? "First" : "Second") << endl;
    return 0;
}
0