QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552073 | #9255. Python Program | ucup-team159# | AC ✓ | 320ms | 11008kb | Python3 | 1.1kb | 2024-09-07 20:18:41 | 2024-09-07 20:18:41 |
Judging History
answer
import sys
import re
l = sys.stdin.readlines()
(i, a, b, c) = re.fullmatch(
'\s*for (.*) in range\(([-0-9a-z]*),([-0-9a-z]*)(|,[-0-9a-z]*)\):\s*', l[1]).groups()
(j, d, e, f) = re.fullmatch(
'\s*for (.*) in range\(([-0-9a-z]*),([-0-9a-z]*)(|,[-0-9a-z]*)\):\s*', l[2]).groups()
if len(c) == 0:
c = '1'
else:
c = c[1:]
if len(f) == 0:
f = '1'
else:
f = f[1:]
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)
"""
# src_slow = f"""
# ans = 0
# for {i} in range({a}, {b}, {c}):
# for {j} in range({d}, {e}, {f}):
# ans += {j}
# print(ans)
# """
# src_deb = f"""
# ans = 0
# for {i} in range({a}, {b}, {c}):
# buf = 0
# for {j} in range({d}, {e}, {f}):
# buf += {j}
# print({i}, buf)
# ans += buf
# print(ans)
# """
exec(src)
# exec(src_deb)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 10976kb
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: 15ms
memory: 11008kb
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: 320ms
memory: 10968kb
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: 11004kb
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: 293ms
memory: 10892kb
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