QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184639 | #5661. Multi-Ladders | SayedHassan# | WA | 1ms | 3512kb | C++14 | 2.2kb | 2023-09-21 00:48:09 | 2023-09-21 00:48:09 |
Judging History
answer
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
#define row vector<ll>
#define matrix vector<row>
matrix zero(int n,int m)
{
matrix ret=matrix(n,row(m,0));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
ret[i][j]=0;
}
}
return ret;
}
matrix id(int n)
{
matrix ret=zero(n,n);
for(int i=0;i<n;i++)ret[i][i]++;
return ret;
}
matrix mul(const matrix &a,const matrix &b)
{
matrix ret=zero(a.size(),b[0].size());
for(int i=0;i<a.size();i++)
{
for(int j=0;j<b[0].size();j++)
{
for(int k=0;k<b.size();k++)
{
ret[i][j]+=a[i][k]*b[k][j];
ret[i][j]%=MOD;
}
}
}
return ret;
}
matrix power(const matrix &a,int p)
{
if(!p)return id(a.size());
if(p&1)return mul(power(a,p-1),a);
return power(mul(a,a),p/2);
}
ll power(ll a,ll p)
{
ll ret=1;
while(p)
{
if(p&1)ret=(ret*a)%MOD;
a=(a*a)%MOD;
p/=2;
}
return ret;
}
int calc(int x,int lst,int rem)
{
if(rem==0)return 1;
int ret=0;
for(int i=1;i<=5;i++)
{
if(i==lst)continue;
if(i==x&&rem==1)continue;
ret+=calc(x,i,rem-1);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin>>t;
while(t--)
{
ll n,k,c;
cin>>n>>k>>c;
if(c<2)
{
cout<<0<<'\n';
continue;
}
if(c==2&&k%2)
{
cout<<0<<'\n';
continue;
}
ll tmp=power((c-2)*(c-3)+(c-2)*2+1,n-1);
tmp=power(tmp,k);
tmp*=power(2,MOD-2);
tmp%=MOD;
ll rep=c*power(c-1,k-1);
//cout<<rep<<endl;
rep%=MOD;
matrix mtx=zero(2,2),p=zero(2,2);
mtx[0][1]=1;
p[0][0]=c-1;
p[0][1]=-(c-1);
mtx=mul(mtx,power(p,k-2));
rep-=mtx[0][0];
rep+=MOD;
rep%=MOD;
cout<<(tmp*rep)%MOD<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3440kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3512kb
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 332394752 433680531 52489881 186358669 740808844 345035876 432643302 830581091 162807454 426059111 995965242 0 0 876190432
result:
wrong answer 7th lines differ - expected: '349400141', found: '332394752'