Submission #5545331


Source Code Expand

import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    R, C, N = map(int, line_input())
    u, l, r, d = [], [], [], []
    for i in range(N):
        x, y, z, w = map(int, line_input())
        if x == 0:
            if z == 0: 
                u.append((x, y, i))
                u.append((z, w, i))
            elif w == C:
                u.append((x, y, i))
                r.append((z, w, i))
            elif z == R:
                u.append((x, y, i))
                d.append((z, w, i))
            elif w == 0:
                u.append((x, y, i))
                l.append((x, y, i))
        elif x == R:
            if z == 0: 
                d.append((x, y, i))
                u.append((z, w, i))
            elif w == C:
                d.append((x, y, i))
                r.append((z, w, i))
            elif z == R:
                d.append((x, y, i))
                d.append((z, w, i))
            elif w == 0:
                d.append((x, y, i))
                l.append((x, y, i))
        elif y == 0:
            if z == 0: 
                l.append((x, y, i))
                u.append((z, w, i))
            elif w == C:
                l.append((x, y, i))
                r.append((z, w, i))
            elif z == R:
                l.append((x, y, i))
                d.append((z, w, i))
            elif w == 0:
                l.append((x, y, i))
                l.append((x, y, i))
        elif y == C:
            if z == 0: 
                r.append((x, y, i))
                u.append((z, w, i))
            elif w == C:
                r.append((x, y, i))
                r.append((z, w, i))
            elif z == R:
                r.append((x, y, i))
                d.append((z, w, i))
            elif w == 0:
                r.append((x, y, i))
                l.append((x, y, i))
    u.sort()
    r.sort()
    d.sort(reverse = True)
    l.sort(reverse = True)

    s = []
    used = set()
    crossed = True
    for point in u:
        if point[2] not in used:
            s.append(point[2])
            used |= {point[2]}
        else:
            if s[-1] != point[2]: break
            else: s.pop()
    else:
        for point in r:
            if point[2] not in used:
                s.append(point[2])
                used |= {point[2]}
            else:
                if s[-1] != point[2]: break
                else: s.pop()
        else:
            for point in d:
                if point[2] not in used:
                    s.append(point[2])
                    used |= {point[2]}
                else:
                    if s[-1] != point[2]: break
                    else: s.pop()
            else:
                for point in l:
                    if point[2] not in used:
                        s.append(point[2])
                        used |= {point[2]}
                    else:
                        if s[-1] != point[2]: break
                        else: s.pop()
                else: crossed = False

    print("NO" if crossed else "YES")
                            
    return 0
  
if __name__ == "__main__":
    solve()

Submission Info

Submission Time
Task E - Connected?
User earlgrey_yh
Language Python (3.4.3)
Score 0
Code Size 3338 Byte
Status WA
Exec Time 498 ms
Memory 38140 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 4
AC × 26
WA × 12
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 43.txt, 44.txt, 45.txt, 46.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt WA 385 ms 25452 KB
02.txt WA 361 ms 22360 KB
03.txt WA 355 ms 22976 KB
04.txt WA 236 ms 9428 KB
05.txt WA 350 ms 22220 KB
06.txt WA 475 ms 33464 KB
07.txt AC 220 ms 6596 KB
08.txt AC 381 ms 24904 KB
09.txt AC 267 ms 13876 KB
10.txt AC 444 ms 31100 KB
11.txt AC 386 ms 26404 KB
12.txt WA 196 ms 3364 KB
13.txt WA 219 ms 7716 KB
14.txt AC 301 ms 16344 KB
15.txt AC 305 ms 17048 KB
16.txt WA 212 ms 5032 KB
17.txt WA 190 ms 3744 KB
18.txt WA 199 ms 3736 KB
19.txt AC 247 ms 10712 KB
20.txt AC 479 ms 33104 KB
21.txt AC 287 ms 14696 KB
22.txt AC 305 ms 16436 KB
23.txt AC 442 ms 32700 KB
24.txt AC 447 ms 34072 KB
25.txt WA 497 ms 37832 KB
26.txt AC 464 ms 34652 KB
27.txt AC 495 ms 37596 KB
28.txt AC 458 ms 34336 KB
29.txt AC 498 ms 37508 KB
30.txt AC 495 ms 38140 KB
43.txt AC 21 ms 3364 KB
44.txt AC 21 ms 3364 KB
45.txt AC 21 ms 3364 KB
46.txt AC 21 ms 3364 KB
s1.txt AC 21 ms 3364 KB
s2.txt AC 21 ms 3364 KB
s3.txt AC 21 ms 3364 KB
s4.txt AC 21 ms 3364 KB