結果

問題 No.7 プライムナンバーゲーム
ユーザー koba-e964koba-e964
提出日時 2015-05-02 14:44:10
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,372 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 89,084 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 05:00:35
合計ジャッジ時間 2,856 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 37 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 25 ms
4,376 KB
testcase_13 AC 28 ms
4,376 KB
testcase_14 RE -
testcase_15 AC 35 ms
4,376 KB
testcase_16 AC 32 ms
4,380 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) {
    REP(i, 0, n + 1) {
      a[i] = 1;
    }
    a[0] = a[1] = 0;
    int c = 2;
    while (c <= n) {
      if (a[c] == 0) {
	c++;
	continue;
      }
      REP(i, 2, (n + 1) / c + 1) {
	a[i * c] = 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