没过样例却过了题?
查看原帖
没过样例却过了题?
639085
SSqwq_楼主2024/8/9 15:59

神奇

#include<bits/stdc++.h>
#define int long long
const int SIZE=(1<<21)+1;
char ibuf[SIZE],obuf[SIZE],*iS,*iT,*oS=obuf,*oT=obuf;
char* flush(){fwrite(obuf,1,oT-oS,stdout);return oT=obuf;}
struct Flusher{~Flusher(){flush();}}flusher;
# define gc() (iS==iT && (iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),iS==iT)?EOF:*iS++)
# define pc(c) ((oT==oS+SIZE && flush()),*oT++=(c))
int read(){
	bool neg=false;
	int x=0;
	char ch=gc();
	if(ch=='-')neg=true;
	for(;(ch<'0' || ch>'9')&&ch!='-';ch=gc());
	for(;(ch>='0' && ch<='9')||ch=='-';ch=gc()){
		if(ch=='-'){
			neg=true;
			continue;
		}
		x=x*10+ch-'0';
	}
	if(neg==true)return 0-x;
	return x;
}
void write(int x){
	if(x<0){
		pc('-');
		x=0-x;
	}
	if(x>=10)write(x/10);
	pc(x%10+'0');
}
using namespace std;
const int p=998244353;
const int N=6001;
int T,n,m,ans,inv6[6001];
int dp[1001][6001];
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1){
			b--;
			res*=a;
			res%=p;
		}
		a*=a;
		a%=p;
		b=(b>>1);
	}
	return res;
}
int inv(int x){
	return qpow(x,p-2);
}
//int C(int a,int b){
//	return (fac[b]*((facinv[b-a]*facinv[a])%p))%p;
//}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	fac[0]=1;
	inv6[0]=inv(1);
//	pw5[0]=1;
	for(int i=1;i<=N-1;++i){
		inv6[i]=inv(qpow(6,i)%p);
//		pw5[i]=pw5[i-1]*5;
//		pw5[i]%=p;
//		fac[i]=fac[i-1]*i;
//		fac[i]%=p;
	}
//	facinv[N-1]=inv(fac[N-1]);
//	for(int i=N-2;i>=0;--i){
//		facinv[i]=(facinv[i+1]*(i+1))%p;
//	}
	dp[0][0]=1;
	for(int i=1;i<=1000;++i){
		for(int j=i;j<=i*6;++j){
			dp[i][j]+=dp[i-1][j-6];
			dp[i][j]+=dp[i-1][j-5];
			dp[i][j]+=dp[i-1][j-4];
			dp[i][j]+=dp[i-1][j-3];
			dp[i][j]+=dp[i-1][j-2];
			dp[i][j]+=dp[i-1][j-1];
			dp[i][j]%=p;
		}
	}
	T=read();
	while(T--){
		n=read(),m=read();
		int x=dp[n][m];
		x*=inv6[n];
		x%=p;
		ans^=x;
	}
	write(ans);
	pc('\n');
	return 0;
}

2024/8/9 15:59
加载中...