QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641307 | #9255. Python Program | 11d10xy | AC ✓ | 137ms | 3968kb | C++14 | 980b | 2024-10-14 19:46:45 | 2024-10-14 19:46:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
int main(){
scanf("ans=0");
int a,b,c=1;char t[50]{};
scanf(" %[^\n\r]",t);
sscanf(t,"for %*c in range(%d,%d,%d):",&a,&b,&c);
char s[3][10]{};
scanf(" %[^\n\r]",t);
sscanf(t,"for %*c in range(%[a-z0-9],%[a-z0-9],%[-a-z0-9]):",s[0],s[1],s[2]);
if(!s[2][0])s[2][0]='1';
i64 ans=0;
auto calc=[&](int i)->i64{
int a[3];
for(int o:{0,1,2}){
if(islower(s[o][0]))a[o]=i;
else sscanf(s[o],"%d",&a[o]);
}
if(a[2]>0){
if(a[0]>=a[1])return 0;
i64 k=(a[1]-1-a[0])/a[2];
return(a[0]+a[0]+k*a[2])*(k+1)/2;
}else{
if(a[0]<=a[1])return 0;
i64 k=(a[0]-1-a[1])/(-a[2]);
return(a[0]+a[0]+k*a[2])*(k+1)/2;
}
};
if(c>0){
for(int i=a;i<b;i+=c)ans+=calc(i);
}else{
for(int i=a;i>b;i+=c)ans+=calc(i);
}
printf("%lld",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3912kb
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: 0ms
memory: 3896kb
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: 110ms
memory: 3708kb
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: 30ms
memory: 3756kb
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: 137ms
memory: 3968kb
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