結果

問題 No.7 プライムナンバーゲーム
ユーザー 🐬hec🐬hec
提出日時 2016-12-25 01:16:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 757 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 163,996 KB
実行使用メモリ 7,612 KB
最終ジャッジ日時 2023-08-21 08:43:52
合計ジャッジ時間 8,370 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 i = 0;
    while(P[i] > N) i++;

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

int main(){    
    cin >> N;
    prime( N );
    cout <<  ( dfs( 0, N ) ? "Win" : "Lose" ) << endl;    
    return 0;
}
0