結果

問題 No.7 プライムナンバーゲーム
ユーザー wakapaijazzwakapaijazz
提出日時 2020-02-16 18:25:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 1,173 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 201,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:31:05
合計ジャッジ時間 2,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

bool isPrime(int x){
    if(x==0 || x==1) return false;
    int rx = floor(sqrt(x));    
    rep3(i,2,rx){
        if(x%i==0) return false;
    }
    return true;
}

void Main(){
    int n;
    cin >> n;
    vector<bool> res(n+10);
    res[0] = res[1] = true;
    res[2] = false;
    rep3(i,3,n) {
        res[i] = false;
        rep3(j,2,i-2){
            if(!res[i-j] && isPrime(j)) {
                res[i] = true;
                break;
            }
        }
    }
    //rep(i,n) if(res[i]) cout << i << endl;
    //*
    if(res[n]) cout << "Win" << endl;
    else cout << "Lose" << endl;
    //*/
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}
0