Submission #217050

# Submission time Handle Problem Language Result Execution time Memory
217050 2020-03-28T18:37:04 Z sevlll Strange Device (APIO19_strange_device) PyPy
100 / 100
3054 ms 188124 KB
from sys import stdin


def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
    if x > y:
        x, y = y, x
    return gcd(y % x, x)



n, a, b = map(int, stdin.readline().split())
pr = []
for i in range(n):
    x, y = map(int, stdin.readline().split())
    pr.append((x, y))
g = gcd(a, b+1)
num = a * b // g
ev = []
ans = 0
for p in pr:
    l = p[0]
    r = p[1]
    if r - l + 1 >= num:
        ans = num
    l %= num
    r %= num
    if r < l:
        ev += [(l, 1), (num, -1), (0, 1), (r+1, -1)]
    else:
        ev += [(l, 1), (r + 1, -1)]
ev.sort()
bal = 0
last = 0
for p in ev:
    x = p[0]
    tp = p[1]
    if bal: ans += x - last
    last = x
    bal += tp
print min(num, ans)
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5080 KB Output is correct
2 Correct 72 ms 13188 KB Output is correct
3 Correct 73 ms 9652 KB Output is correct
4 Correct 26 ms 4960 KB Output is correct
5 Correct 27 ms 4960 KB Output is correct
6 Correct 28 ms 4960 KB Output is correct
7 Correct 27 ms 4960 KB Output is correct
8 Correct 27 ms 4960 KB Output is correct
9 Correct 28 ms 4952 KB Output is correct
10 Correct 26 ms 4960 KB Output is correct
11 Correct 27 ms 4952 KB Output is correct
12 Correct 27 ms 4960 KB Output is correct
13 Correct 27 ms 4960 KB Output is correct
14 Correct 29 ms 4960 KB Output is correct
15 Correct 27 ms 4960 KB Output is correct
16 Correct 71 ms 9608 KB Output is correct
17 Correct 219 ms 28008 KB Output is correct
18 Correct 26 ms 4960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4960 KB Output is correct
2 Correct 27 ms 4960 KB Output is correct
3 Correct 29 ms 4960 KB Output is correct
4 Correct 27 ms 4960 KB Output is correct
5 Correct 29 ms 4960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 4952 KB Output is correct
2 Correct 60 ms 5208 KB Output is correct
3 Correct 46 ms 5336 KB Output is correct
4 Correct 47 ms 5472 KB Output is correct
5 Correct 3054 ms 188124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4928 KB Output is correct
2 Correct 2019 ms 180248 KB Output is correct
3 Correct 2020 ms 176804 KB Output is correct
4 Correct 1978 ms 178312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4928 KB Output is correct
2 Correct 2019 ms 180248 KB Output is correct
3 Correct 2020 ms 176804 KB Output is correct
4 Correct 1978 ms 178312 KB Output is correct
5 Correct 29 ms 4952 KB Output is correct
6 Correct 1934 ms 173456 KB Output is correct
7 Correct 1970 ms 180128 KB Output is correct
8 Correct 1929 ms 175304 KB Output is correct
9 Correct 1923 ms 172940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4928 KB Output is correct
2 Correct 2019 ms 180248 KB Output is correct
3 Correct 2020 ms 176804 KB Output is correct
4 Correct 1978 ms 178312 KB Output is correct
5 Correct 26 ms 5080 KB Output is correct
6 Correct 221 ms 29192 KB Output is correct
7 Correct 216 ms 29192 KB Output is correct
8 Correct 207 ms 29316 KB Output is correct
9 Correct 206 ms 29316 KB Output is correct
10 Correct 226 ms 29316 KB Output is correct
11 Correct 210 ms 29188 KB Output is correct
12 Correct 209 ms 29188 KB Output is correct
13 Correct 212 ms 29192 KB Output is correct
14 Correct 213 ms 29188 KB Output is correct
15 Correct 214 ms 29196 KB Output is correct
16 Correct 213 ms 29188 KB Output is correct
17 Correct 207 ms 29188 KB Output is correct
18 Correct 1932 ms 174572 KB Output is correct
19 Correct 1861 ms 179320 KB Output is correct
20 Correct 1844 ms 173668 KB Output is correct
21 Correct 209 ms 29188 KB Output is correct
22 Correct 222 ms 29316 KB Output is correct
23 Correct 992 ms 68684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 4960 KB Output is correct
2 Correct 212 ms 29188 KB Output is correct
3 Correct 214 ms 29336 KB Output is correct
4 Correct 1843 ms 173504 KB Output is correct
5 Correct 204 ms 29192 KB Output is correct
6 Correct 204 ms 29192 KB Output is correct
7 Correct 208 ms 29188 KB Output is correct
8 Correct 205 ms 29192 KB Output is correct
9 Correct 206 ms 29188 KB Output is correct
10 Correct 209 ms 29192 KB Output is correct
11 Correct 205 ms 29188 KB Output is correct
12 Correct 213 ms 29188 KB Output is correct
13 Correct 217 ms 29444 KB Output is correct
14 Correct 1883 ms 173632 KB Output is correct
15 Correct 213 ms 29316 KB Output is correct
16 Correct 1914 ms 175352 KB Output is correct
17 Correct 1884 ms 175592 KB Output is correct
18 Correct 26 ms 4960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5080 KB Output is correct
2 Correct 72 ms 13188 KB Output is correct
3 Correct 73 ms 9652 KB Output is correct
4 Correct 26 ms 4960 KB Output is correct
5 Correct 27 ms 4960 KB Output is correct
6 Correct 28 ms 4960 KB Output is correct
7 Correct 27 ms 4960 KB Output is correct
8 Correct 27 ms 4960 KB Output is correct
9 Correct 28 ms 4952 KB Output is correct
10 Correct 26 ms 4960 KB Output is correct
11 Correct 27 ms 4952 KB Output is correct
12 Correct 27 ms 4960 KB Output is correct
13 Correct 27 ms 4960 KB Output is correct
14 Correct 29 ms 4960 KB Output is correct
15 Correct 27 ms 4960 KB Output is correct
16 Correct 71 ms 9608 KB Output is correct
17 Correct 219 ms 28008 KB Output is correct
18 Correct 26 ms 4960 KB Output is correct
19 Correct 28 ms 4960 KB Output is correct
20 Correct 27 ms 4960 KB Output is correct
21 Correct 29 ms 4960 KB Output is correct
22 Correct 27 ms 4960 KB Output is correct
23 Correct 29 ms 4960 KB Output is correct
24 Correct 41 ms 4952 KB Output is correct
25 Correct 60 ms 5208 KB Output is correct
26 Correct 46 ms 5336 KB Output is correct
27 Correct 47 ms 5472 KB Output is correct
28 Correct 3054 ms 188124 KB Output is correct
29 Correct 28 ms 4928 KB Output is correct
30 Correct 2019 ms 180248 KB Output is correct
31 Correct 2020 ms 176804 KB Output is correct
32 Correct 1978 ms 178312 KB Output is correct
33 Correct 29 ms 4952 KB Output is correct
34 Correct 1934 ms 173456 KB Output is correct
35 Correct 1970 ms 180128 KB Output is correct
36 Correct 1929 ms 175304 KB Output is correct
37 Correct 1923 ms 172940 KB Output is correct
38 Correct 26 ms 5080 KB Output is correct
39 Correct 221 ms 29192 KB Output is correct
40 Correct 216 ms 29192 KB Output is correct
41 Correct 207 ms 29316 KB Output is correct
42 Correct 206 ms 29316 KB Output is correct
43 Correct 226 ms 29316 KB Output is correct
44 Correct 210 ms 29188 KB Output is correct
45 Correct 209 ms 29188 KB Output is correct
46 Correct 212 ms 29192 KB Output is correct
47 Correct 213 ms 29188 KB Output is correct
48 Correct 214 ms 29196 KB Output is correct
49 Correct 213 ms 29188 KB Output is correct
50 Correct 207 ms 29188 KB Output is correct
51 Correct 1932 ms 174572 KB Output is correct
52 Correct 1861 ms 179320 KB Output is correct
53 Correct 1844 ms 173668 KB Output is correct
54 Correct 209 ms 29188 KB Output is correct
55 Correct 222 ms 29316 KB Output is correct
56 Correct 992 ms 68684 KB Output is correct
57 Correct 26 ms 4960 KB Output is correct
58 Correct 212 ms 29188 KB Output is correct
59 Correct 214 ms 29336 KB Output is correct
60 Correct 1843 ms 173504 KB Output is correct
61 Correct 204 ms 29192 KB Output is correct
62 Correct 204 ms 29192 KB Output is correct
63 Correct 208 ms 29188 KB Output is correct
64 Correct 205 ms 29192 KB Output is correct
65 Correct 206 ms 29188 KB Output is correct
66 Correct 209 ms 29192 KB Output is correct
67 Correct 205 ms 29188 KB Output is correct
68 Correct 213 ms 29188 KB Output is correct
69 Correct 217 ms 29444 KB Output is correct
70 Correct 1883 ms 173632 KB Output is correct
71 Correct 213 ms 29316 KB Output is correct
72 Correct 1914 ms 175352 KB Output is correct
73 Correct 1884 ms 175592 KB Output is correct
74 Correct 26 ms 4960 KB Output is correct
75 Correct 29 ms 4960 KB Output is correct
76 Correct 28 ms 4960 KB Output is correct
77 Correct 26 ms 4960 KB Output is correct
78 Correct 27 ms 5088 KB Output is correct
79 Correct 70 ms 9916 KB Output is correct
80 Correct 1857 ms 175464 KB Output is correct
81 Correct 1852 ms 176232 KB Output is correct
82 Correct 1857 ms 174916 KB Output is correct
83 Correct 1829 ms 175200 KB Output is correct
84 Correct 1831 ms 173732 KB Output is correct
85 Correct 1837 ms 174068 KB Output is correct
86 Correct 991 ms 78508 KB Output is correct
87 Correct 26 ms 4832 KB Output is correct