結果
問題 | No.274 The Wall |
ユーザー | ygd. |
提出日時 | 2022-01-13 20:35:17 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,991 bytes |
コンパイル時間 | 133 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 849,164 KB |
最終ジャッジ日時 | 2024-11-17 13:14:08 |
合計ジャッジ時間 | 7,690 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,864 KB |
testcase_01 | AC | 34 ms
52,480 KB |
testcase_02 | AC | 33 ms
52,608 KB |
testcase_03 | MLE | - |
testcase_04 | AC | 33 ms
52,608 KB |
testcase_05 | AC | 33 ms
52,224 KB |
testcase_06 | AC | 32 ms
52,992 KB |
testcase_07 | AC | 33 ms
52,864 KB |
testcase_08 | AC | 33 ms
52,736 KB |
testcase_09 | AC | 34 ms
52,736 KB |
testcase_10 | AC | 33 ms
52,992 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 96 ms
76,672 KB |
testcase_13 | AC | 60 ms
70,912 KB |
testcase_14 | AC | 118 ms
77,440 KB |
testcase_15 | AC | 128 ms
77,232 KB |
testcase_16 | AC | 657 ms
369,244 KB |
testcase_17 | AC | 622 ms
352,288 KB |
testcase_18 | AC | 720 ms
359,560 KB |
testcase_19 | AC | 144 ms
77,388 KB |
testcase_20 | AC | 150 ms
77,588 KB |
testcase_21 | AC | 154 ms
77,440 KB |
testcase_22 | AC | 151 ms
77,440 KB |
testcase_23 | AC | 152 ms
77,440 KB |
testcase_24 | AC | 158 ms
77,652 KB |
testcase_25 | AC | 155 ms
77,684 KB |
ソースコード
import sys #input = sys.stdin.readline #文字列につけてはダメ #input = sys.stdin.buffer.readline #文字列につけてはダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #MOD = pow(10,9) + 7 #MOD = 998244353 #https://atcoder.jp/contests/practice2/submissions/17674275 class scc_graph: def __init__(self, N): self.N = N self.edges = [] def csr(self): start = [0]*(self.N+1) elist = [0]*len(self.edges) for v, w in self.edges: start[v+1] += 1 for i in range(1, self.N+1): start[i] += start[i-1] counter = start.copy() for v, w in self.edges: elist[counter[v]] = w counter[v] += 1 self.start = start self.elist = elist def add_edge(self, v, w): self.edges.append((v, w)) def scc_ids(self): self.csr() N = self.N now_ord = group_num = 0 visited = [] low = [0]*N order = [-1]*N ids = [0]*N parent = [-1]*N stack = [] for i in range(N): if order[i] == -1: stack.append(~i) stack.append(i) while stack: v = stack.pop() if v >= 0: if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(self.start[v], self.start[v+1]): to = self.elist[i] if order[to] == -1: stack.append(~to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: v = ~v if low[v] == order[v]: while True: u = visited.pop() order[u] = N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num-1-x return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups class two_sat: def __init__(self, N): self.N = N self.answer = [] self.scc = scc_graph(2*N) def add_clause(self, i, f, j, g): #f,g = 0/1 (True/False) # assert 0 <= i < self.N # assert 0 <= j < self.N self.scc.add_edge(2*i+(f == 0), 2*j+(g == 1)) self.scc.add_edge(2*j+(g == 0), 2*i+(f == 1)) def satisfiable(self): #これがTrueならts.answerで満たす場合の組み合わせを出力可能 _, ids = self.scc.scc_ids() self.answer.clear() for i in range(self.N): if ids[2 * i] == ids[2 * i + 1]: self.answer.clear() return False self.answer.append(ids[2*i] < ids[2*i+1]) return True def overlap(a,b,c,d): #Trueは被る if b < c: return False if d < a: return False return True def main(): N,M = map(int,input().split()) L = []; R = [] for i in range(N): l,r = map(int,input().split()) #0-index L.append(l) R.append(r) ts = two_sat(N) for i in range(N): #全てのペアをチェックしてOverlapするところが一か所でもあったらダメ for j in range(i+1,N): li0, ri0 = L[i], R[i] lj0, rj0 = L[j], R[j] li1, ri1 = M-1 - ri0, M-1 - li0 lj1, rj1 = M-1 - rj0, M-1 - lj0 #print(li0, ri0, li1, ri1) #print(lj0, rj0, lj1, rj1) if overlap(li0, ri0, lj0, rj0): #0,0が被るのでどちらか ts.add_clause(i, 0, j, 0) if overlap(li0, ri0, lj1, rj1): #0,1が被るのでどちらか ts.add_clause(i, 0, j, 1) if overlap(li1, ri1, lj0, rj0): #1,0が被るのでどちらか ts.add_clause(i, 1, j, 0) if overlap(li1, ri1, lj1, rj1): #1,1が被るのでどちらか ts.add_clause(i, 1, j, 1) if ts.satisfiable(): print('YES') else: print('NO') if __name__ == '__main__': main()