답안 #931615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931615 2024-02-22T07:06:34 Z dnialh Jakarta Skyscrapers (APIO15_skyscraper) PyPy 3
57 / 100
1000 ms 154632 KB
import sys
input = sys.stdin.readline

n, m = map(int, input().split())

adj = [[] for _ in range(n)]
sta = []

power = []
for _ in range(m):
    bi, pi = map(int, input().split())
    adj[bi].append(_)
    sta.append(bi)
    power.append(pi)

seen = [0] * n

pair = set()
amt = 0
st = [(sta[0], 0)]
while not seen[sta[1]]:
    nex = []

    def add(u, v):
        if 0 <= u < n:
            if (u, v) not in pair:
                pair.add((u, v))
                nex.append((u, v))
    
    while st:
        loc, p = st.pop()
        if not seen[loc]:
            seen[loc] = 1
            for u in adj[loc]:
                st.append((loc, power[u]))

        add(loc + p, p)
        add(loc - p, p)

    amt += 1
    st = nex

    if st == [] and not seen[sta[1]]:
        print(-1)
        sys.exit()
    
print(amt - 1)
    
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 18236 KB Output is correct
2 Correct 34 ms 18484 KB Output is correct
3 Correct 29 ms 18760 KB Output is correct
4 Correct 33 ms 18484 KB Output is correct
5 Correct 28 ms 18232 KB Output is correct
6 Correct 37 ms 18200 KB Output is correct
7 Correct 35 ms 18220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 18760 KB Output is correct
2 Correct 29 ms 18604 KB Output is correct
3 Correct 33 ms 18364 KB Output is correct
4 Correct 37 ms 18228 KB Output is correct
5 Correct 28 ms 18388 KB Output is correct
6 Correct 37 ms 18236 KB Output is correct
7 Correct 29 ms 18192 KB Output is correct
8 Correct 32 ms 18328 KB Output is correct
9 Correct 29 ms 18236 KB Output is correct
10 Correct 34 ms 18228 KB Output is correct
11 Correct 47 ms 19252 KB Output is correct
12 Correct 54 ms 19968 KB Output is correct
13 Correct 54 ms 20016 KB Output is correct
14 Correct 82 ms 24096 KB Output is correct
15 Correct 72 ms 23600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18228 KB Output is correct
2 Correct 29 ms 18140 KB Output is correct
3 Correct 32 ms 18164 KB Output is correct
4 Correct 33 ms 18236 KB Output is correct
5 Correct 33 ms 18236 KB Output is correct
6 Correct 33 ms 18204 KB Output is correct
7 Correct 32 ms 18236 KB Output is correct
8 Correct 30 ms 18172 KB Output is correct
9 Correct 32 ms 18192 KB Output is correct
10 Correct 35 ms 18384 KB Output is correct
11 Correct 45 ms 19136 KB Output is correct
12 Correct 46 ms 20008 KB Output is correct
13 Correct 47 ms 20000 KB Output is correct
14 Correct 69 ms 23996 KB Output is correct
15 Correct 65 ms 23400 KB Output is correct
16 Correct 33 ms 18372 KB Output is correct
17 Correct 60 ms 22932 KB Output is correct
18 Correct 37 ms 19016 KB Output is correct
19 Correct 38 ms 18928 KB Output is correct
20 Correct 58 ms 21168 KB Output is correct
21 Correct 38 ms 19316 KB Output is correct
22 Correct 39 ms 18948 KB Output is correct
23 Correct 68 ms 22960 KB Output is correct
24 Correct 91 ms 26172 KB Output is correct
25 Correct 48 ms 19928 KB Output is correct
26 Correct 63 ms 21828 KB Output is correct
27 Correct 78 ms 24128 KB Output is correct
28 Correct 85 ms 26328 KB Output is correct
29 Correct 85 ms 29016 KB Output is correct
30 Correct 61 ms 22856 KB Output is correct
31 Correct 71 ms 26364 KB Output is correct
32 Correct 73 ms 25092 KB Output is correct
33 Correct 113 ms 34732 KB Output is correct
34 Correct 78 ms 32384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 18256 KB Output is correct
2 Correct 28 ms 18248 KB Output is correct
3 Correct 32 ms 18240 KB Output is correct
4 Correct 31 ms 18220 KB Output is correct
5 Correct 31 ms 18196 KB Output is correct
6 Correct 32 ms 18240 KB Output is correct
7 Correct 31 ms 18240 KB Output is correct
8 Correct 28 ms 18376 KB Output is correct
9 Correct 31 ms 18248 KB Output is correct
10 Correct 35 ms 18156 KB Output is correct
11 Correct 37 ms 19520 KB Output is correct
12 Correct 44 ms 19992 KB Output is correct
13 Correct 50 ms 20016 KB Output is correct
14 Correct 68 ms 24108 KB Output is correct
15 Correct 67 ms 23420 KB Output is correct
16 Correct 35 ms 18256 KB Output is correct
17 Correct 71 ms 22940 KB Output is correct
18 Correct 37 ms 18936 KB Output is correct
19 Correct 34 ms 19000 KB Output is correct
20 Correct 53 ms 21284 KB Output is correct
21 Correct 46 ms 19244 KB Output is correct
22 Correct 34 ms 18740 KB Output is correct
23 Correct 69 ms 22912 KB Output is correct
24 Correct 83 ms 26356 KB Output is correct
25 Correct 50 ms 19936 KB Output is correct
26 Correct 56 ms 21764 KB Output is correct
27 Correct 80 ms 23952 KB Output is correct
28 Correct 78 ms 26160 KB Output is correct
29 Correct 84 ms 28980 KB Output is correct
30 Correct 54 ms 22732 KB Output is correct
31 Correct 82 ms 26184 KB Output is correct
32 Correct 69 ms 24944 KB Output is correct
33 Correct 105 ms 34796 KB Output is correct
34 Correct 85 ms 31128 KB Output is correct
35 Correct 95 ms 28892 KB Output is correct
36 Correct 53 ms 20964 KB Output is correct
37 Correct 98 ms 28512 KB Output is correct
38 Correct 111 ms 30028 KB Output is correct
39 Correct 52 ms 24368 KB Output is correct
40 Correct 85 ms 26444 KB Output is correct
41 Correct 94 ms 28540 KB Output is correct
42 Correct 76 ms 26668 KB Output is correct
43 Correct 95 ms 26584 KB Output is correct
44 Correct 69 ms 26760 KB Output is correct
45 Correct 281 ms 64796 KB Output is correct
46 Correct 181 ms 54740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 18236 KB Output is correct
2 Correct 28 ms 18228 KB Output is correct
3 Correct 34 ms 18184 KB Output is correct
4 Correct 31 ms 18196 KB Output is correct
5 Correct 32 ms 18228 KB Output is correct
6 Correct 30 ms 18296 KB Output is correct
7 Correct 28 ms 18368 KB Output is correct
8 Correct 29 ms 18236 KB Output is correct
9 Correct 29 ms 18276 KB Output is correct
10 Correct 31 ms 18208 KB Output is correct
11 Correct 43 ms 19168 KB Output is correct
12 Correct 45 ms 19972 KB Output is correct
13 Correct 50 ms 19964 KB Output is correct
14 Correct 67 ms 24028 KB Output is correct
15 Correct 69 ms 23436 KB Output is correct
16 Correct 31 ms 18452 KB Output is correct
17 Correct 61 ms 23060 KB Output is correct
18 Correct 39 ms 18972 KB Output is correct
19 Correct 39 ms 18756 KB Output is correct
20 Correct 55 ms 21104 KB Output is correct
21 Correct 38 ms 19228 KB Output is correct
22 Correct 40 ms 19000 KB Output is correct
23 Correct 66 ms 22944 KB Output is correct
24 Correct 86 ms 26352 KB Output is correct
25 Correct 54 ms 20064 KB Output is correct
26 Correct 56 ms 21820 KB Output is correct
27 Correct 88 ms 23904 KB Output is correct
28 Correct 112 ms 26180 KB Output is correct
29 Correct 80 ms 28972 KB Output is correct
30 Correct 57 ms 22816 KB Output is correct
31 Correct 78 ms 26324 KB Output is correct
32 Correct 66 ms 25076 KB Output is correct
33 Correct 117 ms 34824 KB Output is correct
34 Correct 85 ms 31124 KB Output is correct
35 Correct 101 ms 29252 KB Output is correct
36 Correct 67 ms 21036 KB Output is correct
37 Correct 92 ms 28720 KB Output is correct
38 Correct 114 ms 30400 KB Output is correct
39 Correct 57 ms 24496 KB Output is correct
40 Correct 85 ms 26488 KB Output is correct
41 Correct 104 ms 28600 KB Output is correct
42 Correct 92 ms 26672 KB Output is correct
43 Correct 115 ms 26544 KB Output is correct
44 Correct 74 ms 26668 KB Output is correct
45 Correct 292 ms 64692 KB Output is correct
46 Correct 177 ms 54696 KB Output is correct
47 Correct 96 ms 28976 KB Output is correct
48 Correct 53 ms 24624 KB Output is correct
49 Correct 50 ms 24200 KB Output is correct
50 Correct 50 ms 23132 KB Output is correct
51 Correct 178 ms 34696 KB Output is correct
52 Correct 180 ms 37596 KB Output is correct
53 Correct 109 ms 28316 KB Output is correct
54 Correct 50 ms 22832 KB Output is correct
55 Correct 56 ms 25900 KB Output is correct
56 Correct 92 ms 29000 KB Output is correct
57 Correct 53 ms 21040 KB Output is correct
58 Correct 113 ms 34088 KB Output is correct
59 Correct 109 ms 31160 KB Output is correct
60 Correct 121 ms 31088 KB Output is correct
61 Correct 156 ms 32396 KB Output is correct
62 Correct 262 ms 62528 KB Output is correct
63 Execution timed out 1067 ms 154632 KB Time limit exceeded
64 Halted 0 ms 0 KB -