結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | hitoyozake |
提出日時 | 2018-06-03 10:55:02 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 609 ms / 5,000 ms |
コード長 | 1,667 bytes |
コンパイル時間 | 1,189 ms |
コンパイル使用メモリ | 109,832 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-09 04:28:42 |
合計ジャッジ時間 | 5,894 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,948 KB |
testcase_02 | AC | 609 ms
6,944 KB |
testcase_03 | AC | 33 ms
6,944 KB |
testcase_04 | AC | 9 ms
6,944 KB |
testcase_05 | AC | 9 ms
6,944 KB |
testcase_06 | AC | 163 ms
6,944 KB |
testcase_07 | AC | 107 ms
6,944 KB |
testcase_08 | AC | 45 ms
6,948 KB |
testcase_09 | AC | 255 ms
6,948 KB |
testcase_10 | AC | 2 ms
6,948 KB |
testcase_11 | AC | 108 ms
6,944 KB |
testcase_12 | AC | 421 ms
6,944 KB |
testcase_13 | AC | 452 ms
6,948 KB |
testcase_14 | AC | 606 ms
6,948 KB |
testcase_15 | AC | 576 ms
6,948 KB |
testcase_16 | AC | 527 ms
6,944 KB |
ソースコード
#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; for(int i = 2; i <= n; ++i ) { tmp.push_back(i); } while( 1 ) { if(tmp.size()==0) break; int i = tmp[0]; 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){ // std::cout << "win[ " << i << " ] root: " << prime << std::endl; // std::cout << "[i-prime]: " << winlose[i-prime] << std::endl; winlose[i] = true; } } } //for(auto i: primes) // std::cout << i << std::endl; 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; }