結果

問題 No.361 門松ゲーム2
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-23 17:20:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 1,662 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,016 KB
最終ジャッジ日時 2023-11-23 17:20:09
合計ジャッジ時間 5,790 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 66 ms
72,644 KB
testcase_09 AC 79 ms
75,584 KB
testcase_10 AC 65 ms
72,640 KB
testcase_11 AC 57 ms
68,496 KB
testcase_12 AC 67 ms
73,812 KB
testcase_13 AC 67 ms
73,536 KB
testcase_14 AC 315 ms
76,240 KB
testcase_15 AC 83 ms
75,584 KB
testcase_16 AC 348 ms
76,248 KB
testcase_17 AC 232 ms
76,116 KB
testcase_18 AC 105 ms
75,848 KB
testcase_19 AC 176 ms
75,988 KB
testcase_20 AC 82 ms
75,600 KB
testcase_21 AC 274 ms
76,244 KB
testcase_22 AC 641 ms
77,016 KB
testcase_23 AC 168 ms
76,116 KB
testcase_24 AC 169 ms
76,228 KB
testcase_25 AC 263 ms
76,252 KB
testcase_26 AC 326 ms
76,248 KB
testcase_27 AC 317 ms
76,504 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 + 1)
ans = "kado" if dp[L] else "matsu"
print(ans)
0