Submission #5545094


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 gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b

def cross(ax, ay, bx, by, cx, cy, dx, dy): #axaybxbyとcxcydxdyが交差するかどうか
    crossed = True
    if ax >= bx:
        if ax < cx and ax < dx: crossed = False
        elif bx > cx and bx > dx: crossed = False
    else:
        if bx < cx and bx < dx: crossed = False
        elif ax > cx and ax > dx: crossed = False
    if not crossed: return crossed

    if ay >= by:
        if ay < cy and ay < dy: crossed = False
        elif by > cy and by > dy: crossed = False
    else:
        if by < cy and by < dy: crossed = False
        elif ay > cy and ay > dy: crossed = False
    if not crossed: return crossed

    if ((ax-bx)*(cy-ay)+(ay-by)*(ax-cx))*((ax-bx)*(dy-ay)+(ay-by)*(ax-dx)) > 0: crossed = False
    if ((cx-dx)*(ay-cy)+(cy-dy)*(cx-ax))*((cx-dx)*(by-cy)+(cy-dy)*(cx-bx)) > 0: crossed = False
    return crossed

  
def solve():
    R, C, N = map(int, line_input())
    L = []
    for i in range(N):
        x, y, a, b = map(int, line_input())
        if x == 0 or x == R:
            if a == 0 or a == R or b == 0 or b == C: L.append((x, y, a, b))
        elif y == 0 or y == C:
            if a == 0 or a == R or b == 0 or b == C: L.append((x, y, a, b))
    possible = True
    for i in range(len(L)):
        for j in range(i+1, len(L)):
            if cross(L[i][0], L[i][1], L[i][2], L[i][3], L[j][0], L[j][1], L[j][2], L[j][3]):
                print("NO")
                possible = False
                break
        if not possible: break
    else: print("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 1886 Byte
Status WA
Exec Time 614 ms
Memory 21940 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 341 ms 15548 KB
02.txt WA 526 ms 13452 KB
03.txt WA 256 ms 14000 KB
04.txt WA 217 ms 6760 KB
05.txt WA 357 ms 13504 KB
06.txt WA 336 ms 21156 KB
07.txt AC 197 ms 5184 KB
08.txt AC 293 ms 15264 KB
09.txt AC 279 ms 9624 KB
10.txt AC 221 ms 18976 KB
11.txt AC 314 ms 16124 KB
12.txt WA 187 ms 3316 KB
13.txt WA 256 ms 5616 KB
14.txt AC 435 ms 11424 KB
15.txt AC 215 ms 11136 KB
16.txt WA 209 ms 4216 KB
17.txt WA 197 ms 3660 KB
18.txt WA 194 ms 3572 KB
19.txt AC 275 ms 7548 KB
20.txt AC 237 ms 20372 KB
21.txt AC 205 ms 9628 KB
22.txt AC 263 ms 10904 KB
23.txt AC 301 ms 21392 KB
24.txt AC 237 ms 21344 KB
25.txt WA 614 ms 21724 KB
26.txt AC 238 ms 21940 KB
27.txt AC 561 ms 21704 KB
28.txt AC 502 ms 21752 KB
29.txt AC 252 ms 21700 KB
30.txt AC 359 ms 21844 KB
43.txt AC 21 ms 3316 KB
44.txt AC 21 ms 3316 KB
45.txt AC 21 ms 3316 KB
46.txt AC 21 ms 3316 KB
s1.txt AC 21 ms 3316 KB
s2.txt AC 21 ms 3316 KB
s3.txt AC 21 ms 3316 KB
s4.txt AC 21 ms 3316 KB