結果

問題 No.1242 高橋君とすごろく
コンテスト
ユーザー keijak
提出日時 2020-10-03 00:16:24
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,148 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 326 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 35,796 KB
最終ジャッジ日時 2026-04-02 19:55:53
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()


def find_item(x, a):
    if x <= 0:
        return False
    n = len(a)
    for i in range(n - 1, -1, -1):
        if a[i] == x:
            return True
        if a[i] < x:
            break
    return False


def insert_item(x, a):
    if x <= 0:
        return
    if find_item(x, a):
        return
    a.append(x)
    n = len(a)
    for i in range(n - 2, -1, -1):
        if a[i] < a[i + 1]:
            break
        a[i], a[i + 1] = a[i + 1], a[i]


def solve():
    n, k = inl()
    a = inl()
    a.sort()
    deads = set()
    while a:
        x = a.pop()
        if x == 1:
            return False
        if all(x + i in deads for i in range(1, 6)):
            return False
        deads.add(x)
        if find_item(x - 1, a):
            insert_item(x - 4, a)
        if find_item(x - 3, a):
            insert_item(x - 5, a)
        if find_item(x - 5, a):
            insert_item(x - 6, a)
    return True


print("Yes" if solve() else "No")
0