結果

問題 No.7 プライムナンバーゲーム
ユーザー assy1028assy1028
提出日時 2015-03-20 20:04:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,193 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:43:37
合計ジャッジ時間 1,407 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 16 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 4 ms
6,948 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 8 ms
6,948 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 12 ms
6,944 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 16 ms
6,944 KB
testcase_15 AC 15 ms
6,944 KB
testcase_16 AC 14 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;

const int inf = 1000000009;

bool is_prime[10010];
vector<int> primes;
int memo[10010];

void sieve(int n) {
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
	if (is_prime[i]) {
	    primes.push_back(i);
	    for (int j = i + i; j <= n; j += i)
		is_prime[j] = false;
	}
    }
}

bool solve(int n) {
    if (n < 2) return true;
    if (memo[n] == 0) {
	int idx = 0;
	bool win = false;
	while (idx < primes.size() && primes[idx] <= n) {
	    win = (win || !solve(n-primes[idx]));
	    idx++;
	}
	memo[n] = (win ? 1 : -1);
    }
    return memo[n] > 0;
}

int main() {
    int n;
    scanf("%d", &n);
    sieve(n);
    printf("%s\n", solve(n) ? "Win" : "Lose");
}
0