QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554074 | #9255. Python Program | acceon128# | AC ✓ | 332ms | 11100kb | Python3 | 697b | 2024-09-09 04:51:16 | 2024-09-09 04:51:16 |
Judging History
answer
import sys
import re
l = sys.stdin.readlines()
def readline(line):
match = re.fullmatch(r'\s*for (.*) in range\(([-0-9a-z]*),([-0-9a-z]*)(|,[-0-9a-z]*)\):\s*', line)
var, start, end, step = match.groups()
step = step[1:] if step else '1'
return var, start, end, step
(i, a, b, c) = readline(l[1])
(j, d, e, f) = readline(l[2])
src = f"""
ans = 0
for {i} in range({a}, {b}, {c}):
if {f} > 0:
k = ({e} - {d} + {f} - 1) // {f}
elif {f} < 0:
k = ({d} - {e} - {f} - 1) // (-1 * {f})
else:
k = 0
buf = 0
if k > 0:
buf = ({d} + {d} + (k - 1) * {f}) * k // 2
ans += buf
print(ans)
"""
exec(src)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 10888kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 14ms
memory: 10936kb
input:
ans=0 for q in range(100,50,-1): for i in range(q,77,20): ans+=i print(ans)
output:
2092
result:
ok single line: '2092'
Test #3:
score: 0
Accepted
time: 332ms
memory: 11004kb
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)
output:
166666666665500001
result:
ok single line: '166666666665500001'
Test #4:
score: 0
Accepted
time: 45ms
memory: 10944kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
11756963404587200
result:
ok single line: '11756963404587200'
Test #5:
score: 0
Accepted
time: 320ms
memory: 11100kb
input:
ans=0 for i in range(1,1000000): for j in range(i,114514,-1): ans+=j print(ans)
output:
160610445975856765
result:
ok single line: '160610445975856765'
Extra Test:
score: 0
Extra Test Passed