結果

問題 No.274 The Wall
ユーザー maspy
提出日時 2020-03-12 21:58:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 31,280 KB
最終ジャッジ日時 2025-03-17 19:04:45
合計ジャッジ時間 14,411 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from operator import itemgetter

# %%
N, M = map(int, readline().split())
m = map(int, read().split())
LR = zip(m, m)


# %%
def solve(N, M, LR):
    blocks = []
    for L, R in LR:
        L1, R1 = M - 1 - R, M - 1 - L
        if L < L1:
            blocks.append((L, R))
        else:
            blocks.append((L1, R1))
    blocks.sort(key=itemgetter(0))
    A = np.zeros(M, np.int64)
    for L, R in blocks:
        if A[L: R + 1].any():
            A = A[::-1]
            if A[L: R + 1].any():
                return False
        A[L: R + 1] = 1
    return True


# %%
print('YES' if solve(N, M, LR) else 'NO')
0