結果

問題 No.361 門松ゲーム2
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-23 17:19:37
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,662 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,884 KB
最終ジャッジ日時 2023-11-23 17:19:44
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 RE -
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 76 ms
72,644 KB
testcase_09 AC 78 ms
75,584 KB
testcase_10 AC 70 ms
72,640 KB
testcase_11 AC 62 ms
68,496 KB
testcase_12 AC 72 ms
73,812 KB
testcase_13 AC 71 ms
73,664 KB
testcase_14 AC 352 ms
76,240 KB
testcase_15 AC 89 ms
75,584 KB
testcase_16 AC 383 ms
76,244 KB
testcase_17 AC 263 ms
76,244 KB
testcase_18 AC 113 ms
75,848 KB
testcase_19 AC 257 ms
76,372 KB
testcase_20 AC 88 ms
75,604 KB
testcase_21 AC 318 ms
76,244 KB
testcase_22 AC 674 ms
76,884 KB
testcase_23 AC 175 ms
76,124 KB
testcase_24 AC 176 ms
76,228 KB
testcase_25 AC 273 ms
76,244 KB
testcase_26 AC 301 ms
76,244 KB
testcase_27 AC 322 ms
76,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def segfunc(x, y):
    return min(x, y)


class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def add(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


L, D = map(int, input().split())
dp = [0] * (L + 1)
for x in range(1, L + 1):
    Seg = SegTree([i for i in range(L + 1)], segfunc, 1 << 60)
    for a in range(1, x):
        for b in range(a + 1, x):
            c = x - a - b
            if b < c and c - a <= D:
                xor = dp[a] ^ dp[b] ^ dp[c]
                Seg.update(xor, 1 << 60)
    dp[x] = Seg.query(0, L + 2)
ans = "kado" if dp[L] else "matsu"
print(ans)
0