結果

問題 No.7 プライムナンバーゲーム
ユーザー itezpaceitezpace
提出日時 2016-07-14 10:48:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 60,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 17:52:08
合計ジャッジ時間 1,259 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

vector<int> eratos(int a){
  vector<int> ve;
  int arr[a];
  for(int i=0; i<a; ++i){
    arr[i]=1;
  }
  arr[0]=0;
  for(int i=1; i<a; ++i){
    for(int j=2; j*j<=a; ++j){
      if((i+1)!=j && (i+1)%j==0){
        arr[i]=0;
        break;
      }
    }
  }
  for(int i=0; i<a; ++i){
    if(arr[i]==1){
      ve.push_back(i+1);
    }
  }
  return ve;
}

int main(){
  int n;
  cin>>n;
  vector<int> va;
  va=eratos(n);

  int arr[n+1];
  for(int i=0; i<n+1; ++i){
    arr[i]=-1;
  }
  for(int i=0; i<=3; ++i){
    arr[i]=0;
  }

  for(int i=0; i<va.size(); ++i){
    for(int j=n; j>=2; --j){
      if(arr[j]!=-1){
        if(va[i]+j<=n && arr[va[i]+j]!=0 && arr[va[i]+j]<va[i]){
          arr[va[i]+j]=va[i];
        }
      }
    }
  }

  if(arr[n]!=-1){
    int x;
    x=n;
    int c;
    c=0;
    while(1){
      if(x==arr[x] || arr[x]==0){
        break;
      }
      x-=arr[x];
      c++;
    }
    if(c%2==1){
      cout<<"Win"<<endl;
      return 0;
    }
  }
  cout<<"Lose"<<endl;
  return 0;
}
0