結果

問題 No.7 プライムナンバーゲーム
ユーザー goodbatongoodbaton
提出日時 2015-07-15 23:34:17
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,412 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 77,604 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 16:35:14
合計ジャッジ時間 2,116 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 200000

int n;
int dp[10001];
int ans=0;
vector<int> pnum;

const int MAX_P = 10100;
bool prime[MAX_P+1];
void primen(void){
    for(int i=2;i<=MAX_P;i++)
        prime[i]=true;
    
    for(int i=2;i*i<=MAX_P;i++)
        if(prime[i]){
            for(int j=i;i*j<=MAX_P;j++)
                prime[i*j]=false;
            
            pnum.push_back(i);
        }
    
}


int main(){
    
    scanf("%d",&n);
    
    primen();
    
    dp[0]=dp[1]=-1;
    dp[2]=dp[3]=0;
    
    for(int i=4;i<=n;i++){
        vector<int> vec;
        
        for(int j=0;pnum[j]<=i-2;j++){
            vec.push_back(dp[i-pnum[j]]);
        }
        
        sort(vec.begin(),vec.end());
        
        int c=0;
        
        if(vec[0]>0){
            dp[i]=0;
            continue;
        }
        
        while(c<vec.size()-1){
            if(vec[c]+1>=vec[c+1])
                c++;
            else
                break;
        }
        
        dp[i]=vec[c]+1;
        
    }
    
    if(dp[n]==0)
        puts("Lose");
    else
        puts("Win");
    
    return 0;
}
0