QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21386#2819. 摆家具glory_to_the_qy#WA 363ms98064kbC++112.4kb2022-03-04 18:15:482022-05-08 02:58:44

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 02:58:44]
  • 评测
  • 测评结果:WA
  • 用时:363ms
  • 内存:98064kb
  • [2022-03-04 18:15:48]
  • 提交

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;
	}
	for (int i=0;i<20;i++)
		for (int j=0;j<=i;j++) inv[i][j]=qpow(C[i][j],Mod-2);
	cin>>n>>k>>Q; pw[0]=1;
	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<20;i++){
		if (i&&i<=k) 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++)
			ans=(ans+inv[k][i]*dp[now][i][a]%Mod*res.v[i])%Mod;
		cout<<ans<<endl; lastans=ans;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 363ms
memory: 98064kb

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:

87338862
902184791
369861873
682826537
913891032
197381451
575847310
631413540
854149944
661645057
236871568
93999707
804377480
342550672
303776602
860922126
198414071
141969541
466533755
758109943
667626188
365523002
792199025
569758987
877681019
591413001
178788775
231540786
939863235
607718635
45...

result:

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