結果

問題 No.7 プライムナンバーゲーム
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2017-12-14 21:37:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 963 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 82,968 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:24:07
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    int A[10000] = {0};
    vector<int> P;
    for ( int i = 2; i <= N; i++ ) {
        if ( !A[i] ) {
            P.push_back(i);
            for ( int j = 2; i*j <= N; j++ ) {
                A[i*j] = 1;
            }
        }
    }
    
    
    vector<int> W(N+1, 0);
    W[2] = W[3] = 0;
    for ( int i = 4; i <= N; i++ ) {        
        for ( int j = 0; j < P.size() && i-P[j] > 1; j++ ) {
            if ( !W[i-P[j]] ) { W[i] = 1; break; }
        }
    }
    
    // for ( int i = 2; i <= N; i++ ) {
        // cout << W[i] <<endl;
    // }
    
    cout << ( W[N] ? "Win" : "Lose" ) << endl;
    
    
    return 0;
}
0