QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554074#9255. Python Programacceon128#AC ✓332ms11100kbPython3697b2024-09-09 04:51:162024-09-09 04:51:16

Judging History

你现在查看的是最新测评结果

  • [2024-09-09 04:51:16]
  • 评测
  • 测评结果:AC
  • 用时:332ms
  • 内存:11100kb
  • [2024-09-09 04:51:16]
  • 提交

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