結果
問題 | No.274 The Wall |
ユーザー |
|
提出日時 | 2021-12-29 07:33:40 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 644 ms / 2,000 ms |
コード長 | 1,662 bytes |
コンパイル時間 | 128 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 12,032 KB |
最終ジャッジ日時 | 2024-10-03 09:21:07 |
合計ジャッジ時間 | 6,588 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
def scc(N, G, RG):order = []used = [0]*Ngroup = [None]*Ndef dfs(s):used[s] = 1for t in G[s]:if not used[t]:dfs(t)order.append(s)def rdfs(s, col):group[s] = colused[s] = 1for t in RG[s]:if not used[t]:rdfs(t, col)for i in range(N):if not used[i]:dfs(i)used = [0]*Nlabel = 0for s in reversed(order):if not used[s]:rdfs(s, label)label += 1return label, groupdef main():N, M = map(int, input().split())B = [list(map(int, input().split())) for _ in range(N)]g = [[] for _ in range(N*2)]def check(L1, R1, L2, R2, i, j):# AT BTrL1 = M-R1-1rR1 = M-L1-1f1 = f2 = Falseif not (R1 < L2 or R2 < L1):f1 = Trueif not (rR1 < L2 or R2 < rL1):f2 = Trueif f1 and f2:return Falseif f1:g[i].append(j+N)g[i+N].append(j)g[j].append(i+N)g[j+N].append(i)if f2:g[i].append(j)g[i+N].append(j+N)g[j].append(i)g[j+N].append(i+N)return Truefor i in range(N):L1, R1 = B[i]for j in range(i+1, N):L2, R2 = B[j]if not check(L1, R1, L2, R2, i, j):print("NO")return_, nums = scc(N*2, g, g)for i in range(N):if nums[i] == nums[i+N]:print("NO")returnprint("YES")main()