結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2016-12-10 17:19:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 1,563 ms |
コンパイル使用メモリ | 172,048 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:50:55 |
合計ジャッジ時間 | 2,158 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; int N; vector<int> P; vector<vector<int>> visit( 2, vector<int>( 10001, -1 ) );//<---初期化!!! void prime( int N ) { for( int i = 2; i <= N; i++ ) { bool flag = true; for( int j = 2; j * j <= i; j++ ) { if( i % j == 0 ) { flag = false; break; } } if( flag ) { P.emplace_back( i ); } } reverse( P.begin(), P.end() ); } bool dfs( const int T, const int N ) { if( N == 0 || N == 1 ) { return T == 0 ? 1 : 0; } if( visit[ T ][ N ] >= 0 ) { return visit[ T ][ N ]; } if ( T == 0 ) { for( const auto &x : P ) { if( N - x >= 0 ) { if( dfs( 1, N - x ) ) { visit[ T ][ N ] = 1; return 1; } } } visit[ T ][ N ] = 0; return 0; } else { for( const auto &x : P ) { if( N - x >= 0 ) { if( !dfs( 0, N - x ) ) { visit[ T ][ N ] = 0; return 0; } } } visit[ T ][ N ] = 1; return 1; } } int main() { cin >> N; prime( N ); cout << ( dfs( 0, N ) ? "Win" : "Lose" ) << endl; return 0; }