QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677748#9255. Python Programveg#AC ✓3ms3940kbC++201.2kb2024-10-26 13:21:282024-10-26 13:21:28

Judging History

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

  • [2024-10-26 13:21:28]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3940kb
  • [2024-10-26 13:21:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ll long long

const int inf=1e9;

char a[100];
char b[100];
char c[100];

ll solve(int l,int r,int k)
{
	if(k>0)
	{
		r--;
		if(l>r) return 0;	
		int num=(r-l)/k+1;
		return 1ll*(l+l+k*(num-1))*num/2;
	}
	if(k<0)
	{
		r++;
		if(l<r) return 0;
		int num=(l-r)/(-k)+1;
		return 1ll*(l+l+k*(num-1))*num/2;	
	}
}

int main()
{
	scanf("%*s");
	char ch;int l1,r1,k1=1;
	scanf(" for %*c in range(%d,%d%c",&l1,&r1,&ch);
	if(ch==')') scanf(":");	
	else scanf("%d):",&k1);
	int l2=inf,r2=inf,k2=inf;
	scanf(" for %*c in range(%[^,],%[^,)]%c",a,b,&ch);
	if(ch==')') k2=1;
	else scanf("%[^)]):",c);
	if(isdigit(a[0])||a[0]=='-') sscanf(a,"%d",&l2);
	if(isdigit(b[0])||b[0]=='-') sscanf(b,"%d",&r2);
	if(isdigit(c[0])||c[0]=='-') sscanf(c,"%d",&k2);
	ll ans=0;
	if(k1>0)
	{
		for(int i=l1;i<r1;i+=k1)
		{
			int l3=l2==inf?i:l2;
			int r3=r2==inf?i:r2;
			int k3=k2==inf?i:k2;
			ans+=solve(l3,r3,k3);
		}
	}
	else
	{
		for(int i=l1;i>r1;i+=k1)
		{
			int l3=l2==inf?i:l2;
			int r3=r2==inf?i:r2;
			int k3=k2==inf?i:k2;
			ans+=solve(l3,r3,k3);	
		}
	}
	printf("%lld\n",ans);
	return 0;	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

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

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: 3ms
memory: 3940kb

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: 1ms
memory: 3864kb

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: 3ms
memory: 3780kb

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