結果

問題 No.7 プライムナンバーゲーム
ユーザー ferinferin
提出日時 2017-01-27 22:14:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 909 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 161,952 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:10:11
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

bool pdp[10010];
int dp[10010];
vector<int> prime(){
	vector<int> ret;
	for (int i = 2; i < 10010; i++)
	{
		if (pdp[i]) continue;
		ret.push_back(i);
		for (int j = i + i; j < 10010; j += i)
		{
			pdp[j] = true;
		}
	}
	return ret;
}

int main(void)
{
  int n;
  cin >> n;
  auto p = prime();
  dp[0] = dp[1] = true;
  FOR(i, 2, n+1) {
    for(int j: p) {
      if(i - j < 0) break;
      dp[i] |= !dp[i-j];
    }
  }

  if(dp[n]) cout << "Win" << endl;
  else cout << "Lose" << endl;

  return 0;
}
0