CODE FESTIVAL 2016 Exhibition

Submission #1301167

Source codeソースコード

n = input()
D = [tuple(map(int, raw_input().split())) for i in xrange(n)]
if (not D[0][0] == D[1][1] == 0 or not D[0][1] == D[1][0] > 0
        or any(i>1 and (d[0] == 0 or d[1] == 0) for i, d in enumerate(D))):
    print -1
    exit(0)
m = {}
for i, d in enumerate(D):
    m[d] = m.get(d, 0) + 1 if i>0 else 0
P = D[:2]
D.sort()

cnt = 0
for x, y in D:
    if (x+1, y+1) in m:
        cnt += m[x+1, y+1]
        m[x+1, y+1] = 0
    if (x+1, y-1) in m:
        cnt += m[x+1, y-1]
        m[x+1, y-1] = 0

def dfs(x, y, dd, used):
    used.add((x, y))
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if (nx, ny) in m and (nx, ny) not in used:
            dfs(nx, ny, dd, used)
usedA = set(); usedB = set()
dfs(P[0][0], P[0][1], [(1, 1), (1, 0), (1, -1)], usedA)
dfs(P[1][0], P[1][1], [(1, 1), (0, 1), (-1, 1)], usedB)
if len(m) == len(usedA) == len(usedB):
    print 2*n - 2 - cnt
else:
    print -1

Submission

Task問題 A - Distance Pairs
User nameユーザ名 tjake
Created time投稿日時
Language言語 Python2 (2.7.6)
Status状態 RE
Score得点 0
Source lengthソースコード長 948 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 0 / 1500 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,01-31.txt,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 417 ms 24508 KB
01-02.txt AC 423 ms 10944 KB
01-03.txt AC 11 ms 2696 KB
01-04.txt AC 11 ms 2696 KB
01-05.txt AC 15 ms 2820 KB
01-06.txt WA
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt AC 389 ms 12224 KB
01-12.txt AC 405 ms 11764 KB
01-13.txt RE
01-14.txt RE
01-15.txt RE
01-16.txt AC 318 ms 10628 KB
01-17.txt WA
01-18.txt AC 321 ms 10628 KB
01-19.txt RE
01-20.txt RE
01-21.txt RE
01-22.txt RE
01-23.txt AC 455 ms 11832 KB
01-24.txt AC 455 ms 11832 KB
01-25.txt AC 241 ms 10628 KB
01-26.txt AC 238 ms 10628 KB
01-27.txt AC 259 ms 10628 KB
01-28.txt AC 256 ms 10628 KB
01-29.txt AC 10 ms 2696 KB
01-30.txt AC 10 ms 2696 KB
01-31.txt AC 10 ms 2696 KB
sample-01.txt AC 10 ms 2696 KB
sample-02.txt AC 10 ms 2696 KB