这还有优化空间吗
查看原帖
这还有优化空间吗
1125000
wuming_z楼主2024/8/18 15:07

极限速度1.13s

为尽量减少赋值次数,使用了传引用。亲测位运算甚至比此版本慢0.1s,printf慢0.01s

有没有dalao能给他优化到1s内

记录:目前极限

#include <bits/stdc++.h>
using namespace std;
#define maxn 1<<16
int now=maxn;
char in[maxn];
int ans,n,ls;
inline void getch(char &a){
	if(now==maxn){
		fread(in,maxn,1,stdin);
		now=0;
	}
	a=in[now++];
}
inline void read(int &a){
	int out=0;
	bool sf=0;
	char get;
	getch(get);
	while(get<'0'){
	    if(get=='-'){
	        sf=1;
	        break;
	    }
		getch(get);
	}
	while(get<'0'){
		getch(get);
	}
	while(get>='0'){
		out*=10;
		out+=get-'0';
		getch(get);
	}
	if(sf)out=-out;
	a+=out;
}
int main(){
	read(n);
	for(int i=0;i<n;i++){
	    read(ans);
	}
	cout<<ans;
	return 0;
} 
2024/8/18 15:07
加载中...