QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550775#9255. Python Programucup-team1004#AC ✓5ms4176kbC++142.0kb2024-09-07 14:15:322024-09-07 14:15:34

Judging History

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

  • [2024-09-07 14:15:34]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:4176kb
  • [2024-09-07 14:15:32]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1000+5,M=(1<<20)+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int a,b,c,d,e,f;
char C;
int read(){
	int x=0,flag=1;
	while(!isdigit(C)) flag=(C=='-'?-1:1),C=Gc();
	while(isdigit(C)) x=x*10+C-48,C=Gc();
	return x*flag;
}
ll calc(int x,int y,int z){
	gdb(x,y,z);
	if(z<0){
		if(x<=y) return 0;
		z*=-1;
		swap(x,y);
		x=y-(y-x-1)/z*z;
		y++;
	}
	if(x>=y) return 0;
	y=(y-x-1)/z*z+x;
	return 1ll*(x+y)*((y-x)/z+1)/2;
}
void Solve(){
	string s;
	getline(cin,s);
	scanf("for %c in range(%d,%d",&C,&a,&b);
	C=Gc();
	if(C==')') c=1;
	else c=read();
	scanf(":\nfor %c in range(",&C);
	C=Gc();
	gdb(C);
	if(!isdigit(C)) d=0,C=Gc();
	else d=read();
	C=Gc();
	if(!isdigit(C)) e=0,C=Gc();
	else e=read();
	if(C==')') f=1;
	else{
		C=Gc();
		if(!isdigit(C)&&C^'-') f=0;
		else f=read();
	}
	gdb(a,b,c,d,e,f);
	ll ans=0;
	for(int i=a;(c>0?i<b:i>b);i+=c){
		ans+=calc(d?d:i,e?e:i,f?f:i);
	}
	printf("%lld\n",ans);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

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

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: 2ms
memory: 4176kb

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

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: 5ms
memory: 3872kb

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