結果

問題 No.1267 Stop and Coin Game
ユーザー LayCurseLayCurse
提出日時 2020-10-23 22:29:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 2,970 bytes
コンパイル時間 2,622 ms
コンパイル使用メモリ 209,528 KB
実行使用メモリ 13,788 KB
最終ジャッジ日時 2023-09-28 16:33:38
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,420 KB
testcase_01 AC 2 ms
7,456 KB
testcase_02 AC 3 ms
7,464 KB
testcase_03 AC 2 ms
7,688 KB
testcase_04 AC 3 ms
7,536 KB
testcase_05 AC 3 ms
7,548 KB
testcase_06 AC 3 ms
7,584 KB
testcase_07 AC 2 ms
7,448 KB
testcase_08 AC 11 ms
8,032 KB
testcase_09 AC 3 ms
7,608 KB
testcase_10 AC 84 ms
13,788 KB
testcase_11 AC 24 ms
8,472 KB
testcase_12 AC 6 ms
7,664 KB
testcase_13 AC 2 ms
7,472 KB
testcase_14 AC 2 ms
7,452 KB
testcase_15 AC 2 ms
7,516 KB
testcase_16 AC 97 ms
13,532 KB
testcase_17 AC 2 ms
7,596 KB
testcase_18 AC 3 ms
7,480 KB
testcase_19 AC 3 ms
7,448 KB
testcase_20 AC 2 ms
7,456 KB
testcase_21 AC 2 ms
7,472 KB
testcase_22 AC 3 ms
7,468 KB
testcase_23 AC 3 ms
7,452 KB
testcase_24 AC 38 ms
13,604 KB
testcase_25 AC 58 ms
13,604 KB
testcase_26 AC 2 ms
7,456 KB
testcase_27 AC 5 ms
7,548 KB
testcase_28 AC 3 ms
7,584 KB
testcase_29 AC 3 ms
7,460 KB
testcase_30 AC 72 ms
13,584 KB
testcase_31 AC 3 ms
7,440 KB
testcase_32 AC 11 ms
7,968 KB
testcase_33 AC 37 ms
11,540 KB
testcase_34 AC 53 ms
13,668 KB
testcase_35 AC 72 ms
13,724 KB
testcase_36 AC 3 ms
7,412 KB
testcase_37 AC 15 ms
8,168 KB
testcase_38 AC 100 ms
13,548 KB
testcase_39 AC 9 ms
7,672 KB
testcase_40 AC 4 ms
7,420 KB
testcase_41 AC 9 ms
7,708 KB
testcase_42 AC 3 ms
7,456 KB
testcase_43 AC 16 ms
7,972 KB
testcase_44 AC 69 ms
9,456 KB
testcase_45 AC 2 ms
7,536 KB
testcase_46 AC 2 ms
7,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
long long V;
long long A[20];
int ok[1200000];
int dp[1200000];
int main(){
  int mask;
  long long s;
  rd(N);
  rd(V);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(mask=(0);mask<(1<<N);mask++){
    int i;
    s = 0;
    for(i=(0);i<(N);i++){
      if(((mask) &(1<<(i)))){
        s += A[i];
      }
    }
    if(s <= V){
      ok[mask] = 1;
    }
  }
  if(ok[(1<<N)-1]){
    wt_L("Draw");
    wt_L('\n');
    return 0;
  }
  for(mask=(1<<N)-1;mask>=(0);mask--){
    int i;
    if(!ok[mask]){
      dp[mask] = 1;
      continue;
    }
    for(i=(0);i<(N);i++){
      if(!((mask) &(1<<(i)))&& dp[mask ^ (1<<i)] == 0){
        dp[mask] = 1;
        break;
      }
    }
  }
  if(dp[0]){
    wt_L("First");
    wt_L('\n');
  }
  else{
    wt_L("Second");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20201018-2

// --- original code ---
// int N; ll V, A[20];
// int ok[12d5], dp[12d5];
// {
//   ll s;
//   rd(N,V,A(N));
//   rep(mask,1<<N){
//     s = 0;
//     rep(i,N) if(BIT_ith(mask, i)) s += A[i];
//     if(s <= V) ok[mask] = 1;
//   }
//   if(ok[(1<<N)-1]) wt("Draw"), return 0;
// 
//   rrep(mask,1<<N){
//     if(!ok[mask]) dp[mask] = 1, continue;
//     rep(i,N) if(!BIT_ith(mask,i) && dp[mask ^ (1<<i)] == 0) dp[mask] = 1, break;
//   }
// 
//   wt(if[dp[0], "First", "Second"]);
// }
0