結果

問題 No.7 プライムナンバーゲーム
ユーザー CleyLCleyL
提出日時 2022-04-14 08:58:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 80,900 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:07:22
合計ジャッジ時間 1,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 21 ms
6,944 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 4 ms
6,948 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 10 ms
6,948 KB
testcase_10 AC 2 ms
6,948 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 16 ms
6,944 KB
testcase_13 AC 17 ms
6,944 KB
testcase_14 AC 22 ms
6,948 KB
testcase_15 AC 22 ms
6,948 KB
testcase_16 AC 20 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>

using namespace std;
//S
struct SieveEratos{
  vector<int> t;
  SieveEratos(int n):t(n+1,true){
    t[0] = t[1] = 0;
    for(int i = 2; n >= i; i++){
      if(t[i]){
        for(int j = i+i; n >= j; j+=i){
          t[j] = 0;
        }
      }
    }
  }
  bool operator[](int x){return t[x];}
};
//E


int main(){
  int n;cin>>n;
  SieveEratos A(n+1);
  vector<int> p;
  for(int i = 0; n >= i; i++){
    if(A[i]){
      p.push_back(i);
    }
  }
  vector<int> mex(n+1,-1);
  mex[0] = mex[1] = 1;
  for(int i = 2; n >= i; i++){
    vector<int> C(n+1,0);
    for(int j = 0; p.size() > j; j++){
      if(i-p[j] < 0)break;
      C[mex[i-p[j]]] = 1;
    }
    int x = 0;
    while(C[x])x++;
    mex[i] = x;
  }
  // for(int i = 0; n >= i; i++){
  //   cout << mex[i] << " ";
  // }
  // cout << endl;
  if(mex[n]){
    cout << "Win" << endl;
  }else{
    cout << "Lose" << endl;
  }
}
0