为啥我啥也没改,就把getchar();改用cin就可以从0分到AC?
查看原帖
为啥我啥也没改,就把getchar();改用cin就可以从0分到AC?
403619
aigoHZ楼主2021/7/19 17:22

0分:

#include <cstdio>
#include <iostream>
#include <vector>
#define LL long long
#define L long
#define p 998244353
using namespace std;
LL az=0,af=0;
LL cz=1,cf=1;
LL maxfu=-1000000;
vector<LL>fu;
LL ans=0;
L n;
L muchfu=0;
LL read(){
	char ch =getchar();
	LL x=0;
	bool fu=false;
	if(ch=='-'){
		fu=true;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	if(fu){
		return -x;
	}
	return x;
}
int main(){
	n=read();
	for(L i=0;i<n;i++){
		char ch=getchar();
		getchar();
		if(ch=='*'){
			LL x=read();
			if(x>0){
				cz=x*cz%p;
			}else{
				fu.push_back(x);
				muchfu++;
			}
		}else if(ch=='+'){
			LL x=read();
			if(x>0){
				az=(x+az)%p;
			}else{
				af=(x+af)%p;
			}
		}
	}
	int b;
	for(int i=0;i<muchfu;i++){
		if(fu[i]>maxfu){
			maxfu=fu[i];
			b=i;
		}
	}
	for(int i=0;i<muchfu;i++){
		if(i!=b){
			cf=cf*fu[i]%p;
		}
	}
	if(!muchfu){
		ans=(az*cz%p+af)%p;
	}else if(!(muchfu&1)){
		ans=((az*maxfu%p)+af)%p*cf%p*cz%p;
	}else{
		ans=((af*maxfu%p)+az)%p*cf%p*cz%p;
	}
	printf("%lld\n",(ans%p+p)%p);
	return 0;
}

AC:

#include <iostream>
#include <vector>
#define LL long long
#define L long
#define p 998244353
using namespace std;
LL az=0,af=0;
LL cz=1,cf=1;
LL maxfu=-1000000;
vector<LL>fu;
L n;
L muchfu=0;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for(L i=0;i<n;i++){
		char ch;
		LL x;
		cin >> ch >> x; 
		if(ch=='*'){
			if(x>0){
				cz=x*cz%p;
			}else{
				fu.push_back(x);
			}
		}else if(ch=='+'){
			if(x>0){
				az=(x+az)%p;
			}else{
				af=(x+af)%p;
			}
		}
	}
	int b;
	muchfu=fu.size();
	for(int i=0;i<muchfu;i++){
		if(fu[i]>maxfu){
			maxfu=fu[i];
			b=i;
		}
	}
	for(int i=0;i<muchfu;i++){
		if(i!=b){
			cf=cf*fu[i]%p;
		}
	}
	if(!muchfu){
		cout << ((az*cz%p+af)%p+p)%p;
	}else if(!(muchfu&1)){
		cout << (((((az*maxfu%p)+af)%p)*cf%p*cz%p)%p+p)%p;
	}else{
		cout << (((((af*maxfu%p)+az)%p)*cf%p*cz%p)%p+p)%p;
	}
	return 0;
}
2021/7/19 17:22
加载中...