QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139197#5661. Multi-Laddershano#WA 1ms3496kbC++141.8kb2023-08-12 19:37:402023-08-12 19:38:07

Judging History

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

  • [2023-08-12 19:38:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3496kb
  • [2023-08-12 19:37:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

ll sq(ll x){
	return (x*x)%mod;
}
ll bin(ll a,ll b){
	if(b==0)return 1;
	if(b&1){
		return (a*sq(bin(a,b>>1)))%mod;
	}
	return sq(bin(a,b>>1))%mod;
}
struct mat{
	int nn,mm;
	ll a[2][2];
	void init(){
		memset(a,0,sizeof a);
	}
	mat mul(mat b){
		mat res;
		res.init();
		res.nn=nn,res.mm=mm;
		for(int i=0;i<nn;i++){
			for(int j=0;j<mm;j++){
				for(int k=0;k<nn;k++){
					res.a[i][j]+=a[i][k]*b.a[k][j];
					res.a[i][j]%=mod;
				}
			}
		}
		return res;
	}
};

mat sqm(mat x){
	return x.mul(x);
}
mat binm(mat a,ll b){
	if(b==0){
		mat id;
		id.init();
		id.nn=2,id.mm=2;
		id.a[0][0]=1,id.a[1][1]=1;
		return id;
	}
	if(b&1){
		return a.mul(sqm(binm(a,b>>1)));
	}
	return sqm(binm(a,b>>1));
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int t;
	cin>>t;
	while(t--){
		ll n,k,l;cin>>n>>k>>l;
		if(k%2 && l==2){	
			cout<<0<<endl;
			continue;
		}
		if(l<2){
			cout<<0<<endl;
			continue;
		}
		ll ans=0;
		/*
		ll ans=l*(l-2);
		ans%=mod;
		ans*=bin(l-1,k-2);
		ans%=mod;
		if(k!=3)ans+=(l*bin(l-1,k-1))%mod,ans%=mod;
		*/
		ll base=l*(l-1);
		base%=mod;
		base*=(l-2);
		base%=mod;
		mat a;
		a.init();
		a.nn=2,a.mm=2;
		a.a[0][0]=0,a.a[0][1]=1,a.a[1][0]=l-1,a.a[1][1]=l-2;
		mat res=binm(a,k-3);
		/*for(int i=1;i<2;i++){
			for(int j=0;j<2;j++){
				ans+=res.a[1][j]*base;
				ans%=mod;
			}
		}
		*/
		ll bs=n*(n-1);
		bs%=mod;
		ans+=res.a[1][0]*bs;
		ans%=mod;
		ans+=res.a[1][1]*base;
		ans%=mod;
		if(l==2){
			ans=2;
		}
		if(n==1){
			cout<<ans<<endl;
			continue;
		}
		ll hnhn=(l-2)*(l-3);
		hnhn%=mod;
		hnhn+=(l-1)*2-1;
		hnhn%=mod;
		hnhn=bin(hnhn,n-1);
		hnhn%=mod;
		ans*=bin(hnhn,k);
		ans%=mod;
		cout<<ans<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3468kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3496kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
6
0
0
0
0
349400141
123442391
52489881
563914613
176686901
984324326
558243892
97880054
60491853
85313115
338874668
0
0
458677960

result:

wrong answer 8th lines differ - expected: '243010659', found: '123442391'