結果

問題 No.1149 色塗りゲーム
ユーザー Kiri8128Kiri8128
提出日時 2020-07-06 22:11:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 24,712 KB
平均クエリ数 20.92
最終ジャッジ日時 2023-09-24 03:47:35
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,944 KB
testcase_01 AC 57 ms
24,316 KB
testcase_02 AC 56 ms
24,548 KB
testcase_03 AC 55 ms
24,040 KB
testcase_04 AC 57 ms
24,212 KB
testcase_05 AC 58 ms
24,040 KB
testcase_06 AC 57 ms
24,300 KB
testcase_07 AC 56 ms
24,332 KB
testcase_08 AC 57 ms
24,536 KB
testcase_09 AC 58 ms
24,128 KB
testcase_10 AC 60 ms
23,856 KB
testcase_11 AC 60 ms
24,004 KB
testcase_12 AC 59 ms
24,592 KB
testcase_13 AC 59 ms
24,440 KB
testcase_14 AC 60 ms
24,692 KB
testcase_15 AC 60 ms
24,036 KB
testcase_16 AC 62 ms
24,472 KB
testcase_17 AC 61 ms
24,432 KB
testcase_18 AC 62 ms
24,564 KB
testcase_19 AC 62 ms
24,492 KB
testcase_20 AC 62 ms
24,088 KB
testcase_21 AC 62 ms
23,980 KB
testcase_22 AC 62 ms
24,496 KB
testcase_23 AC 62 ms
24,680 KB
testcase_24 AC 63 ms
24,608 KB
testcase_25 AC 63 ms
24,308 KB
testcase_26 AC 63 ms
24,180 KB
testcase_27 AC 64 ms
24,292 KB
testcase_28 AC 64 ms
24,212 KB
testcase_29 AC 63 ms
24,040 KB
testcase_30 AC 105 ms
23,820 KB
testcase_31 AC 106 ms
24,392 KB
testcase_32 AC 109 ms
24,712 KB
testcase_33 AC 117 ms
24,020 KB
testcase_34 AC 114 ms
24,180 KB
testcase_35 AC 117 ms
24,068 KB
testcase_36 AC 116 ms
24,400 KB
testcase_37 AC 122 ms
23,820 KB
testcase_38 AC 119 ms
23,828 KB
testcase_39 AC 127 ms
24,116 KB
testcase_40 AC 131 ms
24,068 KB
testcase_41 AC 130 ms
24,272 KB
testcase_42 AC 133 ms
24,120 KB
testcase_43 AC 133 ms
23,732 KB
testcase_44 AC 138 ms
24,052 KB
testcase_45 AC 139 ms
23,756 KB
testcase_46 AC 138 ms
24,384 KB
testcase_47 AC 145 ms
23,752 KB
testcase_48 AC 142 ms
24,004 KB
testcase_49 AC 146 ms
24,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mex(S):
    a = 0
    while 1:
        if a not in S:
            return a
        a += 1

X = [0]
for i in range(1, 101):
    S = set()
    S.add(X[i-1])
    if i >= 2: S.add(X[i-2])
    for j in range(1, i - 1):
        S.add(X[j] ^ X[i - j - 1])
    for j in range(1, i - 2):
        S.add(X[j] ^ X[i - j - 2])
    X.append(mex(S))

def grundy(Y, i, j):
    nY = Y[:]
    nY[j] = 1
    if i == 2: nY[j+1] = 1
    tmp = [len(a) for a in ("".join(map(str, nY))).split("1") if a]
    s = 0
    for t in tmp:
        s ^= X[t]
    return s

def calc(Y):
    F = [(1, j) for j in range(N)] + [(2, j) for j in range(N - 1)]
    ans = (-1, -1)
    for i, j in F:
        if Y[j]: continue
        if i == 2 and Y[j+1]: continue
        if grundy(Y, i, j) == 0:
            Y[j] = 1
            if i == 2: Y[j+1] = 1
            return (i, j)
        if ans == (-1, -1):
            ans = (i, j)
    
    i, j = ans
    Y[j] = 1
    if i == 2: Y[j+1] = 1
    return ans

N = int(input())
Y = [0] * N
while 1:
    k, x = calc(Y)
    print(k, x + 1)
    t = int(input())
    if t <= 1:
        break
    k, x = map(int, input().split())
    Y[x-1] = 1
    if k == 2: Y[x] = 1
0