結果

問題 No.7 プライムナンバーゲーム
ユーザー 🐬hec🐬hec
提出日時 2016-12-25 01:27:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 811 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 163,992 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 17:11:01
合計ジャッジ時間 4,073 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int N,M;
int P[10010];

void prime(int N){
    for(int i= N ; i>=2; i--){
        bool flag = true;
        for( int j = 2; j * j <= i; j++){
            if( i % j == 0 ){
                flag = false;
                break;
            }
        }
        if(flag) P[M++]=i;
    }
}

bool dfs( const int T, const int N){
    if( N <= 1) return T^1;
    int low = 0, high= M;
    
    while(high-low>1){
        const int mid=(low+high)/2;
        if(P[mid] > N)
            low=mid;
        else
            high=mid;
    }

    int i = high;
    
    while(i < M ){
        int x = P[i++];
        if(T^dfs(T^1, N - x )) return T^1;
    }

    return T;
}

int main(){    
    scanf("%d",&N);
    prime( N );
    puts(dfs(0, N)? "Win" : "Lose" );
    return 0;
}
0