QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85862 | #5661. Multi-Ladders | u2x1 | AC ✓ | 2ms | 3436kb | C++14 | 1.2kb | 2023-03-08 18:45:36 | 2023-03-08 18:45:38 |
Judging History
answer
#include <iostream>
#include <cstring>
#define orep(i,l,r) for(auto i = (l); i < (r); ++i)
#define NL std::cout << '\n';
const int mod = 1e9+7;
long long n, k, r;
struct Mat { int x, y; long long val[3][3]; };
Mat operator*(const Mat &a, const Mat &b) {
Mat ret { a.x, b.y, {} }; memset(ret.val, 0, sizeof(ret.val));
orep(i, 0, a.x) {
orep(j, 0, b.y) {
orep(z, 0, a.y) {
ret.val[i][j] = ((a.val[i][z]*b.val[z][j]%mod) + ret.val[i][j]) % mod;
}
}
}
return ret;
}
long long calR() {
Mat retm = { 2, 2, { {1, 0}, {0, 1}} },
a = { 2, 2, { {r-2, 1}, {r-1, 0}} };
long long kk = k-1;
while(kk) {
if (kk&1) { retm = retm*a; }
kk/=2; a=a*a;
}
return (r*(r-1)%mod) * retm.val[0][1] % mod;
}
long long calL() {
long long ret = 1, a = ((r-2)*(r-2)%mod+(r-1)%mod) % mod;
long long kk = k*(n-1);
while(kk) {
if (kk&1) { ret = ret*a%mod; }
kk/=2; a=a*a%mod;
}
return ret;
}
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
int t; std::cin >> t;
while(t--) {
std::cin >> n >> k >> r;
std::cout << calR() * calL() % mod; NL;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3436kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3408kb
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 52489881 53690844 176686901 218103365 558243892 991895211 693053429 883715672 80402569 0 0 311752813
result:
ok 20 lines