QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550219#9255. Python Programucup-team3646#AC ✓684ms10700kbPython31.7kb2024-09-07 10:53:192024-09-07 10:53:20

Judging History

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

  • [2024-09-07 10:53:20]
  • 评测
  • 测评结果:AC
  • 用时:684ms
  • 内存:10700kb
  • [2024-09-07 10:53:19]
  • 提交

answer

L1=input()
L2=input()
L3=input()
L4=input()
L5=input()

L2=list(L2.split())

s=list(map(int,L2[3][6:-2].split(",")))
if len(s)==2:
  s.append(1)

L3=list(L3.split())
t=list(L3[3][6:-2].split(","))
if len(t)==2:
  t.append("1")

def calc(start,goal,diff):
  # tousa-suuretu no wa
  if diff>0:
    if start>=goal:
      return 0
    n=(goal-start-1)//diff+1
    return n*(2*start+(n-1)*diff)//2
  else:
    diff=abs(diff)
    if start<=goal:
      return 0
    n=(start-goal-1)//diff+1
    return n*(2*start+(n-1)*-diff)//2

def naive(start,goal,diff):
  if diff>0:
    s=0
    now=start
    while now<goal:
      s+=now
      now+=diff
    return s
  s=0
  now=start
  while now>goal:
    s+=now
    now+=diff
  return s

# import random
# while True:
#   a=random.randint(-10,10)
#   b=random.randint(-10,10)
#   c=random.randint(-10,10)
#   if c==0:
#     continue
#   s=calc(a,b,c)
#   t=naive(a,b,c)
#   if s!=t:
#     print(s,t,a,b,c)
#     exit()  
#   print(s,t)


ans=0
if s[2]>0:
  L=s[0]
  R=s[1]
  d=s[2]
  now=L
  while now<R:
    if t[0]==L2[1]:
      start=now
    else:
      start=int(t[0])
    if t[1]==L2[1]:
      goal=now
    else:
      goal=int(t[1])
    if t[2]==L2[1]:
      diff=now
    else:
      diff=int(t[2])
    ans+=calc(start,goal,diff)
    now+=d
  print(ans)
  exit()
else:
  L=s[0]
  R=s[1]
  d=s[2]
  now=L
  while now>R:
    if t[0]==L2[1]:
      start=now
    else:
      start=int(t[0])
    if t[1]==L2[1]:
      goal=now
    else:
      goal=int(t[1])
    if t[2]==L2[1]:
      diff=now
    else:
      diff=int(t[2])
    ans+=calc(start,goal,diff)
    now+=d
  print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 10700kb

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: 10576kb

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: 676ms
memory: 10532kb

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: 126ms
memory: 10608kb

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: 684ms
memory: 10636kb

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