結果

問題 No.361 門松ゲーム2
ユーザー tcltk
提出日時 2021-06-06 07:14:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 89,728 KB
最終ジャッジ日時 2024-11-22 11:28:37
合計ジャッジ時間 6,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

def get_grundy(L):
    if L < 6:
        return 0
    if L in Memo:
        return Memo[L]
    
    s = set()
    for a in range(1, L//3-1 + 1):
        for b in range(a+1, (L-a-1)//2 + 1):
            c = L - a - b
            if c - a <= D:
                s.add(get_grundy(a) ^ get_grundy(b) ^ get_grundy(c))
    mex = 0
    while mex in s:
        mex += 1
    Memo[L] = mex
    return mex

Memo = collections.defaultdict(int)
L, D = map(int, input().split())
g = get_grundy(L)
if g == 0:
    print('matsu')
else:
    print('kado')
0