結果

問題 No.1208 anti primenumber game
ユーザー beet
提出日時 2020-08-30 13:18:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 2,864 ms
コンパイル使用メモリ 203,440 KB
最終ジャッジ日時 2025-01-13 21:03:55
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  auto as=read(n);

  const Int INF = 1e18;
  vector<map<Int, Int>> dp(n);
  MFP([&](auto dfs,Int x,Int v)->Int{
    if(x==n) return 0;
    if(dp[x].count(v)) return dp[x][v];
    Int &res=dp[x][v];
    res=-INF;

    // take all
    chmax(res,-dfs(x+1,as[x+1])+(v-m));

    // remain r
    for(Int r:{1,4,6,8,9,10})
      if(r<v) chmax(res,-dfs(x,r)+(v-r));

    return res;
  })(0,as[0]);
  cout<<(dp[0][as[0]]>0?"First":"Second")<<newl;
  return 0;
}
0