QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139159 | #5661. Multi-Ladders | hano# | WA | 1ms | 3648kb | C++20 | 1.7kb | 2023-08-12 18:34:58 | 2023-08-12 18:35:01 |
Judging History
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);
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;
}
}
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*=(n-1);
hnhn%=mod;
ans*=bin(hnhn,k);
ans%=mod;
cout<<ans<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3648kb
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 965210898 -820981165 999917063 53690844 176686901 459077893 536307325 85889404 120984426 628915545 942349424 0 0 887070036
result:
wrong answer 7th lines differ - expected: '349400141', found: '965210898'