結果
問題 | No.274 The Wall |
ユーザー | tjake |
提出日時 | 2020-10-18 20:58:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 152 ms / 2,000 ms |
コード長 | 1,871 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 78,592 KB |
最終ジャッジ日時 | 2024-07-21 06:44:16 |
合計ジャッジ時間 | 3,134 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,096 KB |
testcase_01 | AC | 35 ms
52,096 KB |
testcase_02 | AC | 35 ms
52,096 KB |
testcase_03 | AC | 46 ms
61,952 KB |
testcase_04 | AC | 39 ms
52,352 KB |
testcase_05 | AC | 38 ms
52,224 KB |
testcase_06 | AC | 40 ms
52,096 KB |
testcase_07 | AC | 34 ms
52,096 KB |
testcase_08 | AC | 36 ms
52,352 KB |
testcase_09 | AC | 36 ms
52,096 KB |
testcase_10 | AC | 38 ms
52,224 KB |
testcase_11 | AC | 46 ms
62,720 KB |
testcase_12 | AC | 73 ms
68,352 KB |
testcase_13 | AC | 52 ms
61,824 KB |
testcase_14 | AC | 79 ms
72,704 KB |
testcase_15 | AC | 103 ms
77,184 KB |
testcase_16 | AC | 47 ms
62,336 KB |
testcase_17 | AC | 46 ms
62,208 KB |
testcase_18 | AC | 46 ms
62,208 KB |
testcase_19 | AC | 127 ms
77,568 KB |
testcase_20 | AC | 152 ms
78,208 KB |
testcase_21 | AC | 137 ms
78,336 KB |
testcase_22 | AC | 142 ms
78,080 KB |
testcase_23 | AC | 137 ms
77,568 KB |
testcase_24 | AC | 143 ms
78,592 KB |
testcase_25 | AC | 145 ms
78,464 KB |
ソースコード
import sys readline = sys.stdin.readline write = sys.stdout.write sys.setrecursionlimit(10**5) def scc(N, G, RG): order = [] used = [0]*N group = [None]*N def dfs(s): used[s] = 1 for t in G[s]: if not used[t]: dfs(t) order.append(s) def rdfs(s, col): group[s] = col used[s] = 1 for t in RG[s]: if not used[t]: rdfs(t, col) for i in range(N): if not used[i]: dfs(i) used = [0]*N label = 0 order.reverse() for s in order: if not used[s]: rdfs(s, label) label += 1 return label, group def solve(): N, M = map(int, readline().split()) S = [tuple(map(int, readline().split())) for i in range(N)] G = [[] for i in range(2*N)] RG = [[] for i in range(2*N)] def add_edge(i, neg_i, j, neg_j): if neg_i: i0 = i+N; i1 = i else: i0 = i; i1 = i+N if neg_j: j0 = j+N; j1 = j else: j0 = j; j1 = j+N G[i1].append(j0); RG[j0].append(i1) G[j1].append(i0); RG[i0].append(j1) for i in range(N): li, ri = S[i] for j in range(i+1, N): lj, rj = S[j] p = q = 0 if (li <= rj and lj <= ri): add_edge(i, 0, j, 0) add_edge(i, 1, j, 1) p = 1 if (li <= M-1-lj and M-1-rj <= ri): add_edge(i, 0, j, 1) add_edge(i, 1, j, 0) q = 1 if p and q: write("NO\n") return label, group = scc(2*N, G, RG) ok = 1 for i in range(N): if group[i] == group[i+N]: ok = 0 break if ok: write("YES\n") else: write("NO\n") solve()