QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#320645#5661. Multi-Laddersushg8877TL 0ms3816kbC++20831b2024-02-03 19:25:072024-02-03 19:25:08

Judging History

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

  • [2024-02-03 19:25:08]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3816kb
  • [2024-02-03 19:25:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MOD=1e9+7;
ll n,k,c; 
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;} 
struct matrix{
	ll a[2][2];
	matrix(){memset(a,0,sizeof(a));}
};
matrix operator *(matrix A,matrix B){
	matrix C;
	for(int i:{0,1}) for(int j:{0,1}) for(int k:{0,1}){
		C.a[i][j]+=A.a[i][k]*B.a[k][j];
		C.a[i][j]%=MOD;
	}
	return C;
}
void solve(){
	cin>>k>>n>>c;
	matrix A,B;
	A.a[0][0]=1;
	B.a[0][0]=0;B.a[0][1]=1;
	B.a[1][0]=c-1;B.a[1][1]=c-2;
	for(int i=0;i<=62;i++){
		if((n-1)>>i&1) A=A*B;
		B=B*B;
	} 
	cout<<c*(c-1)%MOD*A.a[0][1]%MOD*ksm(((c-1)*(c-1)-(c-2))%MOD,n*(k-1))%MOD<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	int _;cin>>_;
	while(_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: -100
Time Limit Exceeded

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
243010659

result: