結果

問題 No.2551 2, 3, 5, 7 Game
ユーザー Seed57_cashSeed57_cash
提出日時 2023-11-21 21:49:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,357 ms
コード長 1,892 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 85,028 KB
最終ジャッジ日時 2023-11-21 21:49:17
合計ジャッジ時間 2,754 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 40 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 227 ms
85,016 KB
testcase_06 AC 207 ms
85,016 KB
testcase_07 AC 207 ms
85,020 KB
testcase_08 AC 206 ms
85,016 KB
testcase_09 AC 192 ms
85,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from bisect import bisect_left


def solve(t, n_list):
    borders = [2, 14]
    while True:
        borders.append(borders[-1] * 2)
        borders.append(borders[-1] * 7)
        if borders[-1] > 10 ** 16:
            break
    res = []
    for n in n_list:
        i = bisect_left(borders, n)
        if i % 2 == 0:
            res.append("ryota")
        else:
            res.append("sepa")
    return res


def solve_tle(t, n_list):
    reduce_dict = {
        2: -1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,
        10: 1, 11: 1, 12: 1, 13: 1, 14: 1, 15: -1
    }
    h = []
    for n in n_list:
        heappush(h, -n)
    while len(h):
        p = heappop(h)
        p *= -1
        if p in reduce_dict.keys():
            continue
        else:
            reduce_dict[p] = 0
        for d in [2, 3, 5, 7]:
            q = (p + d - 1) // d
            if q in reduce_dict.keys():
                continue
            else:
                heappush(h, -q)
    # print(len(reduce_dict))
    for p in sorted(reduce_dict.keys()):
        if reduce_dict[p] != 0:
            continue
        r = -1
        for d in [2, 3, 5, 7]:
            q = (p + d - 1) // d
            if reduce_dict[q] == -1:
                r = 1
        reduce_dict[p] = r
    # for p in sorted(reduce_dict.keys()):
    #     print(p, reduce_dict[p])
    res = []
    for n in n_list:
        if reduce_dict[n] == 1:
            res.append("sepa")
        else:
            res.append("ryota")
    return res


def main():
    t = int(input())
    n_list = [int(input()) for _ in range(t)]
    res = solve(t, n_list)
    for r in res:
        print(r)


def test():
    assert solve(3, [11, 2, 2357]) == ["sepa", "ryota", "sepa"]
    # print([(i + 2, r) for i, r in enumerate(solve(10000, [i + 2 for i in range(10000)]))])


if __name__ == "__main__":
    test()
    main()
0