Task: | Grid Paths II |
Sender: | niketin |
Submission time: | 2020-09-19 16:56:15 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.04 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
Code
import sys def g(xi, yi, n, traps, m): m[(n, n)] = 1 q = [] r = 2*(n) for i in range(r, 1, -1): for x in range(i-1, 0, -1): if 1>x or x > n: continue y = i - x if 1>y or y > n: continue if traps.get((x, y)) is not None: m[(x, y)] = 0 continue if x == n and y == n: continue a=0 b=0 if x < n : u = (x+1,y) if m.get(u) is not None: a = m[u] else: a = g(x+1,y,n,traps,m) if y < n : u = (x,y+1) if m.get(u) is not None: b = m[u] else: b = g(x,y+1,n,traps,m) c = a+b m[(x, y)] = c return m[(1,1)] def main(): s = input() (n, traplen)= s.split() n = int(n) traplen = int(traplen) traps = {} for i in range(traplen): s = input() (t1, t2)= s.split() traps[(int(t1), int(t2))] = 1 m = {} result = g(1, 1, n, traps, m) print(result % (10**9 + 7)) if __name__ == "__main__": main()
Test details
Test 1
Verdict: ACCEPTED
input |
---|
100 1000 41 11 11 24 51 72 47 31 ... |
correct output |
---|
342758070 |
user output |
---|
342758070 |
Test 2
Verdict: ACCEPTED
input |
---|
100 1000 83 37 24 1 52 42 86 36 ... |
correct output |
---|
919249325 |
user output |
---|
919249325 |
Test 3
Verdict: ACCEPTED
input |
---|
100 1000 99 28 16 31 92 41 39 65 ... |
correct output |
---|
12649242 |
user output |
---|
12649242 |
Test 4
Verdict: ACCEPTED
input |
---|
100 1000 5 47 32 1 27 70 86 39 ... |
correct output |
---|
466313473 |
user output |
---|
466313473 |
Test 5
Verdict: ACCEPTED
input |
---|
100 1000 14 28 63 16 15 54 68 18 ... |
correct output |
---|
525088588 |
user output |
---|
525088588 |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000 1000 332974 646000 669874 23872 662362 92533 670177 367382 ... |
correct output |
---|
476425733 |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000 1000 474616 793877 452016 207512 940198 719201 162471 997296 ... |
correct output |
---|
757933231 |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000 1000 125814 37785 523915 416397 246681 345297 635386 245404 ... |
correct output |
---|
672607703 |
user output |
---|
(empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000 1000 468197 471455 970002 408761 420246 765021 8126 930827 ... |
correct output |
---|
138494458 |
user output |
---|
(empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000 1000 837278 905086 893778 245584 867013 721507 404988 868333 ... |
correct output |
---|
796948966 |
user output |
---|
(empty) |