結果

問題 No.7 プライムナンバーゲーム
ユーザー 0w10w1
提出日時 2016-11-20 14:15:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 167,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 04:17:00
合計ジャッジ時間 2,689 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 47 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 9 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 35 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 41 ms
4,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