QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550559#9255. Python Programucup-team052#AC ✓3ms3688kbC++232.1kb2024-09-07 13:26:282024-09-07 13:26:28

Judging History

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

  • [2024-09-07 13:26:28]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3688kb
  • [2024-09-07 13:26:28]
  • 提交

answer

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

typedef long long ll;
#define int long long

signed main() {
#ifdef xay5421
	freopen("b.in","r",stdin);
#endif
	char ch;
	int a=0,b=0,c=1,d=0,e=0,f=1;
	while((ch=getchar()))
	{
		if(ch=='(')
		{
			ch=getchar();
			int tne=0;
			if(ch=='-') tne=1,ch=getchar();
			while(isdigit(ch))
			{
				a=a*10+ch-'0';
				ch=getchar();
			}
			if(tne) a=-a,tne=0;
			assert(ch==',');
			ch=getchar();
			if(ch=='-') tne=1,ch=getchar();
			while(isdigit(ch))
			{
				b=b*10+ch-'0';
				ch=getchar();
			}
			if(tne) b=-b,tne=0;
			if(ch==',')
			{
				ch=getchar();
				c=0;
				if(ch=='-') tne=1,ch=getchar();
				while(isdigit(ch))
				{
					c=c*10+ch-'0';
					ch=getchar();
				}
				if(tne) c=-c,tne=0;
			}
			break;
		}
	}
	int fld=0,fle=0,flf=0;
	while((ch=getchar()))
	{
		if(ch=='(')
		{
			ch=getchar();
			int tne=0;
			if(ch=='-') tne=1,ch=getchar();
			if(!isdigit(ch)) fld=1,ch=getchar();
			while(isdigit(ch))
			{
				d=d*10+ch-'0';
				ch=getchar();
			}
			if(tne) d=-d,tne=0;
			assert(ch==',');
			ch=getchar();
			if(ch=='-') tne=1,ch=getchar();
			if(!isdigit(ch)) fle=1,ch=getchar();
			while(isdigit(ch))
			{
				e=e*10+ch-'0';
				ch=getchar();
			}
			if(tne) e=-e,tne=0;
			if(ch==',')
			{
				ch=getchar();
				if(ch=='-') tne=1,ch=getchar();
				f=0;
				if(!isdigit(ch)) flf=1,ch=getchar();
				while(isdigit(ch))
				{
					f=f*10+ch-'0';
					ch=getchar();
				}
				if(tne) f=-f,tne=0;
			}
			break;
		}
	}
	int ans=0;
	auto calc=[&](int d,int e,int f)
	{
		if(f>0)
		{
			if(d>=e) return 0LL;
			int t=(abs(e-d)-1)/abs(f);
			return d*(t+1)+(1+t)*t/2*f;
		}
		else
		{
			if(d<=e) return 0LL;
			int t=(abs(e-d)-1)/abs(f);
			return d*(t+1)+(1+t)*t/2*f;
		}
	};
	// printf("%d %d %d\n",a,b,c);
	// printf("%d %d %d\n",d,e,f);
	if(c>0)
	{
		for(int i=a;i<b;i+=c)
		{
			ans+=calc(fld?i:d,fle?i:e,flf?i:f);
		}
	}
	else
	{
		for(int i=a;i>b;i+=c)
		{
			ans+=calc(fld?i:d,fle?i:e,flf?i:f);
		}
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

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

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

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

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: 0ms
memory: 3624kb

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

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