結果
問題 | No.274 The Wall |
ユーザー | ygd. |
提出日時 | 2022-01-13 20:14:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,248 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2024-11-17 12:43:34 |
合計ジャッジ時間 | 3,279 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,352 KB |
testcase_01 | AC | 40 ms
53,248 KB |
testcase_02 | AC | 39 ms
52,992 KB |
testcase_03 | AC | 47 ms
60,928 KB |
testcase_04 | AC | 38 ms
52,608 KB |
testcase_05 | AC | 40 ms
52,736 KB |
testcase_06 | AC | 41 ms
52,992 KB |
testcase_07 | AC | 43 ms
52,736 KB |
testcase_08 | AC | 44 ms
52,608 KB |
testcase_09 | AC | 40 ms
52,736 KB |
testcase_10 | AC | 43 ms
52,480 KB |
testcase_11 | AC | 46 ms
60,544 KB |
testcase_12 | AC | 89 ms
72,576 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 49 ms
62,208 KB |
testcase_17 | AC | 48 ms
60,672 KB |
testcase_18 | AC | 48 ms
60,544 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 168 ms
77,312 KB |
testcase_23 | AC | 168 ms
77,440 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
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) and overlap(li0, ri0, lj1, rj1): print('NO');exit() if overlap(li1, ri1, lj0, rj0) and overlap(li1, ri1, lj1, rj1): print('NO');exit() if overlap(li0, ri0, lj0, rj0): #0,0が被るのでどちらか ts.add_clause(i, 0, i+1, 0) if overlap(li0, ri0, lj1, rj1): #0,1が被るのでどちらか ts.add_clause(i, 0, i+1, 1) if overlap(li1, ri1, lj0, rj0): #1,0が被るのでどちらか ts.add_clause(i, 1, i+1, 0) if overlap(li1, ri1, lj1, rj1): #1,1が被るのでどちらか ts.add_clause(i, 1, i+1, 1) if ts.satisfiable(): print('YES') else: print('NO') if __name__ == '__main__': main()