Submission #5545409


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((y, i))
                u.append((w, i))
            elif w == C:
                u.append((y, i))
                r.append((z, i))
            elif z == R:
                u.append((y, i))
                d.append((w, i))
            elif w == 0:
                u.append((y, i))
                l.append((z, i))
        elif x == R:
            if z == 0: 
                d.append((y, i))
                u.append((w, i))
            elif w == C:
                d.append((y, i))
                r.append((z, i))
            elif z == R:
                d.append((y, i))
                d.append((w, i))
            elif w == 0:
                d.append((y, i))
                l.append((z, i))
        elif y == 0:
            if z == 0: 
                l.append((x, i))
                u.append((w, i))
            elif w == C:
                l.append((x, i))
                r.append((z, i))
            elif z == R:
                l.append((x, i))
                d.append((w, i))
            elif w == 0:
                l.append((x, i))
                l.append((z, i))
        elif y == C:
            if z == 0: 
                r.append((x, i))
                u.append((w, i))
            elif w == C:
                r.append((x, i))
                r.append((z, i))
            elif z == R:
                r.append((x, i))
                d.append((w, i))
            elif w == 0:
                r.append((x, i))
                l.append((z, i))
    u.sort()
    r.sort()
    d.sort(reverse = True)
    l.sort(reverse = True)

    s = []
    used = set()
    crossed = True
    for point, n in u:
        if n not in used:
            s.append(n)
            used |= {n}
        else:
            if s[-1] != n: break
            else: s.pop()
    else:
        for point, n in r:
            if n not in used:
                s.append(n)
                used |= {n}
            else:
                if s[-1] != n: break
                else: s.pop()
        else:
            for point, n in d:
                if n not in used:
                    s.append(n)
                    used |= {n}
                else:
                    if s[-1] != n: break
                    else: s.pop()
            else:
                for point, n in l:
                    if n not in used:
                        s.append(n)
                        used |= {n}
                    else:
                        if s[-1] != n: 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 700
Code Size 3142 Byte
Status AC
Exec Time 495 ms
Memory 33724 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 4
AC × 38
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 AC 361 ms 22464 KB
02.txt AC 330 ms 19676 KB
03.txt AC 363 ms 20356 KB
04.txt AC 260 ms 8832 KB
05.txt AC 340 ms 19808 KB
06.txt AC 468 ms 32972 KB
07.txt AC 210 ms 6100 KB
08.txt AC 366 ms 22048 KB
09.txt AC 269 ms 12524 KB
10.txt AC 400 ms 27084 KB
11.txt AC 379 ms 23376 KB
12.txt AC 188 ms 3400 KB
13.txt AC 229 ms 7156 KB
14.txt AC 289 ms 14624 KB
15.txt AC 289 ms 15228 KB
16.txt AC 201 ms 4740 KB
17.txt AC 193 ms 3756 KB
18.txt AC 191 ms 3656 KB
19.txt AC 244 ms 9612 KB
20.txt AC 433 ms 28972 KB
21.txt AC 277 ms 13208 KB
22.txt AC 302 ms 15048 KB
23.txt AC 411 ms 28352 KB
24.txt AC 438 ms 29860 KB
25.txt AC 495 ms 33676 KB
26.txt AC 460 ms 30692 KB
27.txt AC 480 ms 33620 KB
28.txt AC 448 ms 30576 KB
29.txt AC 462 ms 33724 KB
30.txt AC 468 ms 33696 KB
43.txt AC 21 ms 3400 KB
44.txt AC 21 ms 3400 KB
45.txt AC 21 ms 3400 KB
46.txt AC 21 ms 3400 KB
s1.txt AC 21 ms 3400 KB
s2.txt AC 21 ms 3400 KB
s3.txt AC 21 ms 3400 KB
s4.txt AC 21 ms 3400 KB