結果

問題 No.7 プライムナンバーゲーム
ユーザー TawaraTawara
提出日時 2016-01-13 11:21:19
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,463 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-09 03:54:42
合計ジャッジ時間 10,687 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,692 KB
testcase_01 AC 12 ms
6,688 KB
testcase_02 AC 1,463 ms
10,624 KB
testcase_03 AC 103 ms
7,296 KB
testcase_04 AC 35 ms
6,912 KB
testcase_05 AC 34 ms
6,912 KB
testcase_06 AC 431 ms
8,704 KB
testcase_07 AC 295 ms
8,192 KB
testcase_08 AC 137 ms
7,552 KB
testcase_09 AC 657 ms
9,088 KB
testcase_10 AC 11 ms
6,688 KB
testcase_11 AC 298 ms
8,192 KB
testcase_12 AC 1,050 ms
9,984 KB
testcase_13 AC 1,116 ms
10,240 KB
testcase_14 AC 1,463 ms
10,624 KB
testcase_15 AC 1,383 ms
10,496 KB
testcase_16 AC 1,277 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,math
sys.setrecursionlimit(10**5)
def sieve(n):
	check = [True]*(n+1)
	check[0] = check[1] = False
	for d in xrange(2,int(math.sqrt(n))+1):
		if not check[d]: continue
		for comp in xrange(d*2,n+1,d):
			check[comp] = False
	return [i for i in xrange(2,n+1) if check[i]]
N = input(); memo = [None]*(N+1); prime = sieve(N)
memo[0] = memo[1] = True
def dfs(n):
	if memo[n] is None:
		tmp = False
		for p in prime:
			if p > n: continue
			tmp |= not dfs(n-p)
		memo[n] = tmp
	return memo[n]
print "Win" if dfs(N) else "Lose"
0