QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102938 | #5661. Multi-Ladders | Joler | WA | 2ms | 3476kb | C++20 | 1.7kb | 2023-05-03 20:23:26 | 2023-05-03 20:23:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#ifdef LOCAL
template<class t,class u>ostream& operator<<(ostream& os,const pair<t,u>& p){return os<<"("<<p.first<<","<<p.second<<")";}
#endif
template<class t>ostream& operator<<(ostream& os,const vector<t>& v){if(v.size())os<<v[0];for(int i=1; i<v.size(); i++)os<<' '<<v[i]; return os;}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;
ll n, m, t, k, a, b, c, d, cnt, mark, an, oT_To, x, y, z;
ll ans;
array<array<ll, 2>, 2> A;
struct jz {
array<array<ll, 2>, 2> a{};
};
jz operator*(const jz& ja, const jz& jb) {
array<array<ll, 2>, 2> res{};
for (int i : {0, 1}) for (int j : {0, 1}) for (int l : {0, 1})
(res[i][j] += ja.a[i][l] * jb.a[l][j] % mod) %= mod;
return {res};
}
jz ksm (jz a, ll b) {
jz res{array<ll, 2>{1, 0}, array<ll, 2>{0, 1}};
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
ll ksm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) (res *= a) %= mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
struct Solver {
void solve() {
cin >> n >> m >> k;
A[0] = {0, 1};
A[1] = {k-1, k-2};
if (k <= 1) return cout << "0\n", void();
auto p = ksm({A}, m-1);
auto r = ((k - 1) * (k - 1) % mod - (k - 2) + mod) % mod;
cout << (p.a[1][0] * k % mod) * ksm(r, k * (n - 1)) % mod << '\n';
}
};
#undef int
int main () {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
oT_To = 1;
cin >> oT_To;
while (oT_To--) {
Solver solver;
solver.solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3284kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3476kb
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 400529194 870104653 52489881 796875060 763101440 595186199 813695696 629251545 693053429 883715672 80402569 0 0 809953857
result:
wrong answer 7th lines differ - expected: '349400141', found: '400529194'