QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95696 | #5661. Multi-Ladders | SGColin# | WA | 2ms | 3852kb | C++20 | 1.1kb | 2023-04-11 14:08:10 | 2023-04-11 14:08:10 |
Judging History
answer
#include <bits/stdc++.h>
using u64 = uint64_t;
const int P = 1e9+7;
struct mint {
int x;
mint(int x = 0):x(x){}
mint operator+(mint o) {return x+o.x<P?x+o.x:x+o.x-P;}
mint operator-(mint o) {return x-o.x<0?x-o.x+P:x-o.x;}
mint operator*(mint o) {return u64(x)*o.x%P;}
mint pow(int k) {
mint a = x;
mint b = 1;
for(; k; k /= 2) {
if(k & 1)
b = b * a;
a = a * a;
}
return b;
}
};
struct matr {
mint a[2][2]{};
matr operator*(matr o) {
matr ans;
for(int i = 0;i<2;++i)
for(int j = 0;j<2;++j)
for(int k = 0;k<2;++k)
ans.a[i][k] = ans.a[i][k] + a[i][j]*o.a[j][k];
return ans;
}
matr pow(int k) {
matr a = *this;
matr b = {1,0,0,1};
for(; k; k /= 2) {
if(k & 1)
b = b * a;
a = a * a;
}
return b;
}
};
int i32() {
int x;
scanf("%d", &x);
return x;
}
int main() {
int T = i32();
while(T--) {
int n = i32();
int k = i32();
mint m = i32();
matr tmp = matr{0,1,m-1,m-2}.pow(n-2)*matr{m,m,0,0};
mint ans = tmp.a[0][0]*(m-1)+tmp.a[1][0]*(m-2);
ans = ans * (m * m - m * 3 + 3).pow(n-1).pow(k);
printf("%d\n", ans.x);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3852kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3692kb
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 2 0 0 619159556 44174210 103570820 415637863 304930780 218103365 294935167 29649047 720 459000000 459000000 0 0 311752813
result:
wrong answer 4th lines differ - expected: '0', found: '2'