結果

問題 No.7 プライムナンバーゲーム
ユーザー hitoyozakehitoyozake
提出日時 2018-06-03 10:13:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 85,152 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 21:45:40
合計ジャッジ時間 2,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

int main()
{
    int n = 0;
    std::cin >> n;

    //邏�謨ー繧呈アゅa繧�
    std::vector<int> primes;
    std::vector<int> tmp(n-2, 0);

    for(int i = 2; i < n; ++i )
    {
        tmp.push_back(i);
    }

    for( int i = 2; i < n; ++i )
    {
        primes.push_back(i);

        if(std::sqrt(n) <= i)
            break;

        std::vector<int> t;

        for(auto x: tmp){
            if(x%i != 0){
                t.push_back(x);
            }
        }

        tmp = t;
    }

    for(auto x: tmp){
        primes.push_back(x);
    }

    //蜍昴■雋�縺僧ap繧剃ス懊k
    std::map<int, bool> winlose;

    winlose[0] = false;
    winlose[1] = false;

    for( int i = 2; i < n; ++i ){
        winlose[i] = false;
        
        for( auto const prime: primes)
        {
            if(prime > i ){
                break;
            }

            if(i-prime >= 2&& winlose[i-prime]==false){
                winlose[i] = true;
                break;
            }
        }
    }
    /*
    for(auto i: winlose){
        std::cout << "winlose[ " << i.first << " ]: " << i.second << std::endl;
    }*/

    std::string wl = "Win";
    if(winlose[n]==false)
        wl = "Lose";

    std::cout << wl << std::endl;


    return 0;
}
0