結果

問題 No.7 プライムナンバーゲーム
ユーザー koba-e964koba-e964
提出日時 2015-05-02 14:46:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,388 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 90,404 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:44:56
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int N = 10010;
int dp[N];

class Sieve {
private:
  std::vector<int> a;
public:
  Sieve(int n) : a(n + 1) {
    for (int i = 0; i <= n; ++i) {
      a[i] = 1;
    }
    a[0] = a[1] = 0;
    int c = 2;
    while (c <= n) {
      if (a[c] == 0) {
	c++;
	continue;
      }
      for(int i = 2 * c; i <= n; i += c) {
	a[i] = 0;
      }
      c++;
    }
  }
  bool operator[] (int x) const {
    return a[x] != 0;
  }
};

Sieve sie(0);

int rec(int n) {
  if (n <= 1) {
    return 1;
  }
  if (dp[n] >= 0) {
    return dp[n];
  }
  REP(i, 2, n) {
    if (sie[i]) {
      if (rec(n - i) == 0) {
	dp[n] = 1;
	return 1;
      }
    }
  }
  dp[n] = 0;
  return 0;
}

int main(void){
  int n;
  cin >> n;
  REP(i, 0, N) dp[i] = -1;
  sie = Sieve(n);
  cout << (rec(n) ? "Win" : "Lose") << endl;
}
0