結果

問題 No.7 プライムナンバーゲーム
ユーザー cureskolcureskol
提出日時 2020-03-23 23:44:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 163,908 KB
実行使用メモリ 13,556 KB
最終ジャッジ日時 2024-04-09 04:51:00
合計ジャッジ時間 2,839 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,176 KB
testcase_01 AC 5 ms
13,304 KB
testcase_02 AC 62 ms
13,300 KB
testcase_03 AC 9 ms
13,300 KB
testcase_04 AC 6 ms
13,428 KB
testcase_05 AC 6 ms
13,300 KB
testcase_06 AC 22 ms
13,172 KB
testcase_07 AC 15 ms
13,172 KB
testcase_08 AC 9 ms
13,424 KB
testcase_09 AC 30 ms
13,552 KB
testcase_10 AC 6 ms
13,428 KB
testcase_11 AC 16 ms
13,300 KB
testcase_12 AC 45 ms
13,556 KB
testcase_13 AC 48 ms
13,428 KB
testcase_14 AC 62 ms
13,424 KB
testcase_15 AC 60 ms
13,428 KB
testcase_16 AC 55 ms
13,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1234567],p[1234567];

bool prime(int a){
  if(~p[a])return p[a];
  for(int i=2;i*i<=a;i++)if(a%i==0)return p[a]=0;
  return p[a]=1;
}

bool f(int a){
  if(a<=1)return 1;
  if(~dp[a])return dp[a];
  for(int i=2;i<=a;i++)if(prime(i)&&!f(a-i))return dp[a]=1;
  return dp[a]=0;
}

int main(){
  int n;cin>>n;
  memset(dp,-1,sizeof(dp));
  memset(p,-1,sizeof(p));
  cout<<(f(n)?"Win":"Lose")<<endl;
}
0