Contest Duration: - (local time) (100 minutes) Back to Home

Submission #8873780

Source Code Expand

Copy
```import sys

from fractions import gcd

if D == 0:
if X == 0:
print(1)
else:
print(N+1)
exit()

g = gcd(X,D)
X //= g; D //= g
if D < 0:
X,D = -X,-D

def F(d):
# Xの個数 = d mod Dのとき
event = []
for n in range(d,N+1,D):
# Xがn個
low = X * n // D + n * (n-1) // 2
high = X * n // D + n * (N+N-n-1) // 2
event.append((low,0))
event.append((high,1))
event.sort()
overlap = 0
left_end = 0
cnt = 0
for x,t in event:
if not t:
if not overlap:
left_end = x
overlap += 1
else:
overlap -= 1
if not overlap:
cnt += x - left_end + 1
return cnt

answer = sum(F(d) for d in range(min(D,N+1)))

#### Submission Info

Submission Time 2019-12-09 00:07:22+0900 F - Sum Difference maspy Python (3.4.3) 600 989 Byte AC 520 ms 49752 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
 AC × 3
 AC × 51
Set Name Test Cases
Sample s1.txt, s2.txt, s3.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, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 36 ms 5072 KB
02.txt AC 35 ms 5072 KB
03.txt AC 35 ms 5072 KB
04.txt AC 35 ms 5072 KB
05.txt AC 35 ms 5072 KB
06.txt AC 36 ms 5072 KB
07.txt AC 35 ms 5072 KB
08.txt AC 35 ms 5072 KB
09.txt AC 35 ms 5072 KB
10.txt AC 35 ms 5072 KB
11.txt AC 35 ms 5072 KB
12.txt AC 35 ms 5072 KB
13.txt AC 35 ms 5072 KB
14.txt AC 35 ms 5072 KB
15.txt AC 35 ms 5072 KB
16.txt AC 35 ms 5072 KB
17.txt AC 35 ms 5072 KB
18.txt AC 36 ms 5072 KB
19.txt AC 35 ms 5072 KB
20.txt AC 35 ms 5072 KB
21.txt AC 36 ms 5072 KB
22.txt AC 36 ms 5072 KB
23.txt AC 365 ms 5072 KB
24.txt AC 378 ms 5072 KB
25.txt AC 322 ms 5072 KB
26.txt AC 418 ms 5072 KB
27.txt AC 308 ms 5072 KB
28.txt AC 520 ms 5072 KB
29.txt AC 493 ms 5072 KB
30.txt AC 516 ms 5072 KB
31.txt AC 386 ms 5072 KB
32.txt AC 339 ms 5072 KB
33.txt AC 319 ms 5108 KB
34.txt AC 305 ms 5108 KB
35.txt AC 332 ms 6260 KB
36.txt AC 357 ms 49752 KB
37.txt AC 349 ms 12788 KB
38.txt AC 358 ms 16244 KB
39.txt AC 373 ms 7188 KB
40.txt AC 372 ms 47940 KB
41.txt AC 339 ms 13940 KB
42.txt AC 346 ms 7264 KB
43.txt AC 339 ms 12508 KB
44.txt AC 356 ms 46936 KB
45.txt AC 345 ms 8660 KB
46.txt AC 478 ms 5072 KB
47.txt AC 492 ms 5072 KB
48.txt AC 36 ms 5072 KB
s1.txt AC 35 ms 5072 KB
s2.txt AC 35 ms 5072 KB
s3.txt AC 36 ms 5072 KB