結果

問題 No.7 プライムナンバーゲーム
ユーザー 0w10w1
提出日時 2016-11-20 14:15:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 168,800 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 10:42:43
合計ジャッジ時間 2,298 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

const string msg[] = { "Lose", "Win" };

int dfs( const vector< int > &np, vector< int > &dp, int u ){
  if( ~dp[ u ] )
    return dp[ u ];
  for( int i = 2; i <= u; ++i )
    if( not np[ i ] )
      if( not dfs( np, dp, u - i ) )
        return dp[ u ] = 1;
  return dp[ u ] = 0;
}

signed main(){
  int N; cin >> N;
  vector< int > np( N + 1 );
  for( int i = 2; i <= N; ++i )
    if( not np[ i ] )
      for( int j = i + i; j <= N; j += i )
        np[ j ] = 1;
  vector< int > dp( N + 1, -1 );
  dp[ 0 ] = dp[ 1 ] = 0; 
  cout << msg[ dfs( np, dp, N ) ] << endl;
  return 0;
}
0