結果

問題 No.1208 anti primenumber game
ユーザー kk
提出日時 2020-09-14 20:28:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 201,120 KB
実行使用メモリ 8,028 KB
最終ジャッジ日時 2023-09-04 00:47:19
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 15 ms
7,932 KB
testcase_16 AC 16 ms
7,856 KB
testcase_17 AC 16 ms
7,832 KB
testcase_18 AC 16 ms
7,788 KB
testcase_19 AC 16 ms
7,860 KB
testcase_20 AC 16 ms
7,724 KB
testcase_21 AC 17 ms
7,784 KB
testcase_22 AC 16 ms
8,028 KB
testcase_23 AC 17 ms
7,832 KB
testcase_24 AC 35 ms
7,720 KB
testcase_25 AC 35 ms
7,740 KB
testcase_26 AC 33 ms
7,728 KB
testcase_27 AC 32 ms
7,740 KB
testcase_28 AC 33 ms
7,876 KB
testcase_29 AC 32 ms
7,748 KB
testcase_30 AC 17 ms
7,860 KB
testcase_31 AC 16 ms
7,836 KB
testcase_32 AC 16 ms
7,728 KB
testcase_33 AC 16 ms
7,924 KB
testcase_34 AC 16 ms
7,744 KB
testcase_35 AC 16 ms
7,876 KB
testcase_36 AC 13 ms
6,728 KB
testcase_37 AC 16 ms
7,892 KB
testcase_38 AC 28 ms
7,800 KB
testcase_39 AC 29 ms
7,728 KB
testcase_40 AC 32 ms
7,792 KB
testcase_41 AC 18 ms
7,920 KB
testcase_42 AC 18 ms
7,852 KB
testcase_43 AC 18 ms
7,728 KB
testcase_44 AC 18 ms
7,792 KB
testcase_45 AC 18 ms
7,876 KB
testcase_46 AC 15 ms
7,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

long long dp[200000][2];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  long long m;
  cin >> n >> m;

  vector<long long> a(n);
  REP (i, n) cin >> a[i];

  dp[n-1][0] = a[n-1] == 1 ? a[n-1] - m : max(a[n-1]-m, a[n-1]-2+m);
  dp[n-1][1] = a[n-1] == 1 ? m - a[n-1] : min(m-a[n-1], 2-a[n-1]-m);

  for (int i = n-2; i >= 0; i--) {
    if (a[i] == 1) {
      dp[i][0] = 1-m + dp[i+1][1];
      dp[i][1] = m-1 + dp[i+1][0];
    } else {
      dp[i][0] = max(a[i]+m-2 + dp[i+1][0], a[i]-m + dp[i+1][1]);
      dp[i][1] = min(-a[i]-m+2 + dp[i+1][1], -a[i]+m + dp[i+1][0]);
    }
  }
  
  if (dp[0][0] > 0)
    cout << "First" << endl;
  else
    cout << "Second" << endl;
    
  return 0;
}
0