結果

問題 No.7 プライムナンバーゲーム
ユーザー cwwcww
提出日時 2016-12-10 17:19:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 168,516 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:05:25
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0