結果

問題 No.7 プライムナンバーゲーム
ユーザー goodbatongoodbaton
提出日時 2015-07-15 23:38:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 1,462 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 77,848 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:47:46
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 148 ms
6,944 KB
testcase_03 AC 11 ms
6,944 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 5 ms
6,948 KB
testcase_06 AC 45 ms
6,944 KB
testcase_07 AC 30 ms
6,948 KB
testcase_08 AC 15 ms
6,944 KB
testcase_09 AC 66 ms
6,944 KB
testcase_10 AC 2 ms
6,948 KB
testcase_11 AC 31 ms
6,944 KB
testcase_12 AC 106 ms
6,948 KB
testcase_13 AC 113 ms
6,948 KB
testcase_14 AC 148 ms
6,944 KB
testcase_15 AC 140 ms
6,944 KB
testcase_16 AC 129 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~

ソースコード

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;
        }
    
}


int main(){
    
    scanf("%d",&n);
    
    primen();
    
    for(int i=2;i<=n+100;i++){
        if(prime[i])
            pnum.push_back(i);
    }
    
    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