QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550523#9255. Python Programucup-team3510#AC ✓3ms3892kbC++201.6kb2024-09-07 13:19:142024-09-07 13:19:15

Judging History

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

  • [2024-09-07 13:19:15]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3892kb
  • [2024-09-07 13:19:14]
  • 提交

answer

#include <bits/stdc++.h>
#define gc getchar
#define ll long long
using namespace std;
void readc(char c){while(gc()!=c);}
char readc()
{
	char ch=gc();
	while(ch<'a'||ch>'z')ch=gc();
	return ch;
}
int readint()
{
	int x=0;char ch=gc();int f=1;
	while(ch<'0'||ch>'9')f=(ch=='-'?-f:f),ch=gc();
	while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=gc();
	return x*f;
}
char I;
const int isI=-1e9;
int a,b,c,d,e,f;
ll calc(int a,int b,int c)
{
	if(c>0)
	{
		--b;
		if(a>b)return 0;
		int tim=(b-a)/c;
		return 1ll*a*(tim+1)+1ll*tim*(tim+1)/2*c;
	}
	else
	{
		++b;
		if(a<b)return 0;
		int tim=(a-b)/(-c);
		return 1ll*a*(tim+1)+1ll*tim*(tim+1)/2*c;
	}
}
ll F(int a,int b,int c)
{
	ll ans=0;
	if(c>0)
	{
		--b;
		if(a>b)return 0;
		for(int i=a;i<=b;i+=c)
		{
			int nd,ne,nf;
			if(d==isI)nd=i;else nd=d;
			if(e==isI)ne=i;else ne=e;
			if(f==isI)nf=i;else nf=f;
			ans+=calc(nd,ne,nf);
		}
	}
	else
	{
		++b;
		if(a<b)return 0;
		for(int i=a;i>=b;i+=c)
		{
			int nd,ne,nf;
			if(d==isI)nd=i;else nd=d;
			if(e==isI)ne=i;else ne=e;
			if(f==isI)nf=i;else nf=f;
			ans+=calc(nd,ne,nf);
		}
	}
	return ans;
}
int main()
{
	readc(10);
	readc('r');
	I=readc();
	readc('(');
	a=readint();
	b=readint();
	if(cin.peek()!=':')c=readint();
	else c=1;
	readc('(');
	if(cin.peek()==I)d=-1e9,gc(),gc();
	else d=readint();
	if(cin.peek()==I)e=-1e9,gc(),gc();
	else e=readint();
	if(cin.peek()==':')f=1;
	else if(cin.peek()==I)f=-1e9,readc(':');
	else f=readint();
	// printf("a:%d b:%d c:%d d:%d e:%d f:%d isI:%d\n",a,b,c,d,e,f,isI);
	printf("%lld\n",F(a,b,c));
	fclose(stdin);fclose(stdout);return 0;
}

详细

Test #1:

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

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

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

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

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

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