QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21405#2819. 摆家具glory_to_the_qyWA 351ms98128kbC++112.5kb2022-03-04 19:46:512022-05-08 03:12:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:12:25]
  • 评测
  • 测评结果:WA
  • 用时:351ms
  • 内存:98128kb
  • [2022-03-04 19:46:51]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int Mod=998244353;
int n,k,Q,m;
ll C[22][22],inv[22][22];
ll dp[2][22][1100000],pw[110];
ll qpow(ll x,int a){
	ll res=1;
	while (a){
		if (a&1) res=res*x%Mod;
		x=x*x%Mod; a>>=1;
	}
	return res;
}
struct Matrix{
	ll v[20][20];
	Matrix(){ memset(v,0,sizeof(v));}
	void init(){
		for (int i=0;i<20;i++) v[i][i]=1;
	}
	Matrix operator*(const Matrix &a) const{
		Matrix res;
		for (int i=0;i<20;i++)
			for (int k=0;k<20;k++)
				if (v[i][k])
					for (int j=0;j<20;j++)
						res.v[i][j]=(res.v[i][j]+v[i][k]*a.v[k][j])%Mod;
		return res;
	}
} A,q[4100];
struct Vector{
	ll v[20];
	Vector(){ memset(v,0,sizeof(v));}
	Vector operator*(const Matrix &a) const{
		Vector res;
		for (int k=0;k<20;k++)
			if (v[k])
				for (int j=0;j<20;j++)
					res.v[j]=(res.v[j]+v[k]*a.v[k][j])%Mod;
		return res;
	}
} p[310000],res;
int bit(int s,int i){ return s/pw[i]%n;}
int calc(int s,int i,int x){ return pw[i]*x+s;}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	for (int i=0;i<20;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;
	}
	cin>>n>>k>>Q; pw[0]=1;
	for (int i=0;i<=k;i++)
		for (int j=0;j<=i;j++) inv[i][j]=qpow(C[i][j]*qpow(n-1,k-i)%Mod,Mod-2);
	for (int i=1;i<=k;i++) pw[i]=pw[i-1]*n;
	m=pw[k]; int now=0;
	for (int i=0;i<m;i++) cin>>dp[0][0][i];
	for (int i=0;i<k;i++){//bit i(0..k-1)
		now^=1;
		for (int s=0;s<=m;s++)
			for (int j=0;j<=i+1;j++)
				dp[now][j][s]=dp[now^1][j][s];
		for (int s=0;s<=m;s++)//status s(without i)
			if (!bit(s,i))
				for (int j=0;j<=i;j++){//dif j
					ll res=0;
					for (int x=0;x<n;x++) res=(res+dp[now^1][j][calc(s,i,x)])%Mod;
//					cerr<<res<<endl;
					for (int x=0;x<n;x++) dp[now][j+1][calc(s,i,x)]=(dp[now][j+1][calc(s,i,x)]+(res+Mod-dp[now^1][j][calc(s,i,x)]))%Mod;
				}
	}
	
	for (int i=0;i<=k;i++){
		if (i) A.v[i-1][i]=(k-i+1)*(n-1);
		if (i<k) A.v[i+1][i]=i+1;
		A.v[i][i]=(n-2)*i;
	}
//	for (int i=0;i<=k;i++){
//		if (i) A.v[i][i-1]=i;
//		if (i<k) A.v[i][i+1]=k-i;
//	}
	p[0].v[0]=1;
	for (int i=0;i<(1<<18);i++) p[i+1]=p[i]*A;
	q[0].init(); int t=18;
	while (t--) A=A*A;
	for (int i=0;i<=4000;i++) q[i+1]=q[i]*A;
	ll lastans=1,a,b;
	while (Q--){
		cin>>a>>b; b=b*lastans%Mod;
		res=p[b&((1<<18)-1)]*q[b>>18];
		
		ll ans=0;
		for (int i=0;i<=k;i++)
//			cerr<<res.v[i]<<'\n';
			ans=(ans+inv[k][i]*dp[now][i][a]%Mod*res.v[i])%Mod;
		cout<<ans<<endl; lastans=ans;
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 351ms
memory: 98128kb

input:

6 7 23333
691899807
511100503
969237388
938904792
350428599
320423686
227132681
288051232
833056445
128207711
81740114
850060462
194951182
130925016
505452669
304380595
703105541
640122112
75295756
128144693
482592240
835507949
68960843
807876145
6134269
259053259
386495729
193956365
370675670
12980...

output:

131629795
432828408
916555521
369927475
52894810
102428682
186899803
250370268
157734231
988487935
389992308
125707703
71651249
870148489
975416880
943548066
931542884
732091667
349648529
171015845
675600850
995767683
4747889
661634250
778617381
486992273
606483551
658576810
624083215
803741092
3464...

result:

wrong answer 1st lines differ - expected: '190581075', found: '131629795'