結果

問題 No.7 プライムナンバーゲーム
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-09 16:46:31
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,571 ms / 5,000 ms
コード長 687 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:42:56
合計ジャッジ時間 11,692 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,820 KB
testcase_01 AC 12 ms
6,948 KB
testcase_02 AC 1,571 ms
6,948 KB
testcase_03 AC 113 ms
6,948 KB
testcase_04 AC 39 ms
6,948 KB
testcase_05 AC 38 ms
6,944 KB
testcase_06 AC 467 ms
6,948 KB
testcase_07 AC 323 ms
6,948 KB
testcase_08 AC 152 ms
6,948 KB
testcase_09 AC 709 ms
6,948 KB
testcase_10 AC 12 ms
6,944 KB
testcase_11 AC 322 ms
6,948 KB
testcase_12 AC 1,122 ms
6,948 KB
testcase_13 AC 1,197 ms
6,944 KB
testcase_14 AC 1,561 ms
6,948 KB
testcase_15 AC 1,484 ms
6,944 KB
testcase_16 AC 1,366 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(raw_input())
isPrime=[True for i in range(N+1)]
isPrime[0]=False
isPrime[1]=False
primes=[]
for i in range (N+1):
   if isPrime[i]:
      primes.append(i)
      for j in range(i+i,N+1,i):
         isPrime[j]=False

grundy=[-1 for i in range(N+1)]
grundy[0]=1
grundy[1]=1
for i in range(2,N+1):
   grundySet=set([])
   for p in primes:
      if i-p < 0:
         break
      grundySet.add(grundy[i-p])
   grundyList= list(grundySet)
   grundyList.sort()
   for v in range(len(grundyList)+1):
      #print v , ",",
      if v==len(grundyList) or grundyList[v]!= v:
         grundy[i]=v
         break
   #print grundy[i], " ",
if grundy[N] == 0:
   print "Lose"
else:
   print "Win"
0