結果

問題 No.7 プライムナンバーゲーム
ユーザー phtmscgphtmscg
提出日時 2019-04-20 00:32:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,634 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-09 04:38:58
合計ジャッジ時間 24,948 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 3,634 ms
11,264 KB
testcase_03 AC 241 ms
11,008 KB
testcase_04 AC 85 ms
10,880 KB
testcase_05 AC 83 ms
10,880 KB
testcase_06 AC 1,066 ms
11,008 KB
testcase_07 AC 689 ms
11,008 KB
testcase_08 AC 320 ms
11,008 KB
testcase_09 AC 1,556 ms
10,880 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 717 ms
11,136 KB
testcase_12 AC 2,540 ms
11,008 KB
testcase_13 AC 2,705 ms
11,008 KB
testcase_14 AC 3,538 ms
11,008 KB
testcase_15 AC 3,284 ms
11,008 KB
testcase_16 AC 3,202 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

P = [0]*2 + [1]*(N-1)
q = []
for n in range(2,N+1):
    if P[n] != 0:
        q.append(n)
        for m in range(n,N+1):
            if P[m] != 0 and m%n == 0:
                P[m] = 0

G = [0]*(N+1)
for i in range(4,N+1):
    g = []
    for j in range(len(q)):
        if q[j] <= i and i-q[j]>1:
            g.append(G[i-q[j]])
        else:
            break

    if len(g) == 0:
        G[i] = 0
    else:
        for x in range(len(g)):
            if x not in g:
                G[i] = x
                break
        else:
            G[i] = len(g)
print("Win" if G[N] != 0 else "Lose")
0