QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217568 | #5661. Multi-Ladders | AnthonyQwO | WA | 1ms | 3640kb | C++14 | 1.2kb | 2023-10-17 00:14:30 | 2023-10-17 00:14:31 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = (int)1e9+7;
int qpow(int n,int k){
int res = 1, base = n;
while(k){
if(k&1) res *= base;
base *= base;
k >>= 1;
}
return res;
}
vector<vector<int>> mulmatrix( vector<vector<int>>& a, vector<vector<int>>& b ) {
int n=a.size(), m=a[0].size(), k=b[0].size();
vector<vector<int>> res(n,vector<int>(k,0));
for( int i=0 ; i < n ; i++ ) {
for( int j=0 ; j < k ; j++ ) {
for( int l=0 ; l < m ; l++ )
res[i][j]=(res[i][j]+a[i][l]*b[l][j]%MOD+MOD)%MOD;
}
}
return res;
}
vector<vector<int>> matrixqpow( vector<vector<int>>& a, int k, int y) {
vector<vector<int>> res={{0},{y, 0}};
while(k) {
if( k&1 ) res=mulmatrix(a,res);
a=mulmatrix(a,a), k>>=1;
}
return res;
}
signed main(){
int L, n, k, y;
cin >> L;
while(L--){
cin >> n >> k >> y;
vector<vector<int>> turn = {{y-2, y-1}, {1, 0}};
cout << (matrixqpow(turn, k-1, y))[0][0] % MOD * qpow(qpow((y-1)+(y-2)*(y-2), n-1), k) % MOD << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
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 -557177115 -993215664 -127945688 -882417393 120036762 269613431 95933688 -407586010 693053429 883715672 80402569 0 0 -204734833
result:
wrong answer 7th lines differ - expected: '349400141', found: '-557177115'