QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#660653 | #9255. Python Program | lllei# | WA | 0ms | 3740kb | C++20 | 2.2kb | 2024-10-20 12:33:38 | 2024-10-20 12:33:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e2+10;
char s[maxn];
char a,b;
long long sum(int l,int r,int c)
{
if(l<r&&c>0)
{
r--;
int s=l,m=(r-l)/c*c+l;
int num=(r-l)/c+1;
return (s+m)*1LL*num/2;
}
else if(l>r&&c<0)
{
r++;
c=-c;
int s=l,m=l-(l-r)/c*c;
int num=(l-r)/c+1;
return (s+m)*1LL*num/2;
}
else return 0;
}
int l1,r1,l2,r2,c1,c2;
int main()
{
scanf("%s",s);
getchar();
scanf("for %c in range(%d,%d",&a,&l1,&r1);
char ch=getchar();
if(ch==')')c1=1;
else
{
int flag=1;
ch=getchar();
if(ch=='-')flag=-1,ch=getchar();
c1=ch-'0';
ch=getchar();
while(ch!=')')
{
c1=c1*10+ch-'0';
ch=getchar();
}
c1*=flag;
}
cout<<ch<<'\n';
getchar();
getchar();
scanf("for %c in range(",&b);
ch=getchar();
if(ch>'9'||ch<'0')l2=-1,ch=getchar();
else
{
l2=ch-'0';
ch=getchar();
while(ch!=',')
{
l2=l2*10+ch-'0';
ch=getchar();
}
}
ch=getchar();
if(ch>'9'||ch<'0')r2=-1,ch=getchar();
else
{
r2=ch-'0';
ch=getchar();
while(ch!=','&&ch!=')')
{
r2=r2*10+ch-'0';
ch=getchar();
}
}
ch=getchar();
if(ch==':')c2=1;
else
{
if((ch>'9'||ch<'0')&&ch!='-')c2=0;
else
{
int flag=1;
if(ch=='-')flag=-1,ch=getchar();
c2=ch-'0';
ch=getchar();
while(ch!=')')
{
c2=c2*10+ch-'0';
ch=getchar();
}
c2=c2*flag;
}
}
if(l1>r1)
{
long long ans=0;
for(int i=l1;i>r1;i+=c1)ans+=sum(l2==-1?i:l2,r2==-1?i:r2,c2==0?i:c2);
printf("%lld\n",ans);
}
else
{
long long ans=0;
for(int i=l1;i<r1;i+=c1)ans+=sum(l2==-1?i:l2,r2==-1?i:r2,c2==0?i:c2);
printf("%lld\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3740kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
) 0
result:
wrong answer 1st lines differ - expected: '16', found: ')'