QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102584 | #5661. Multi-Ladders | Joler# | AC ✓ | 3ms | 3484kb | C++14 | 3.7kb | 2023-05-03 14:51:23 | 2023-05-03 14:51:27 |
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;}
template<class T>
T power(T a, ll b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
template<int P>
struct MInt {
int x;
MInt() : x{} {}
MInt(ll x) : x{norm(x % P)} {}
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
int val() const {
return x;
}
MInt operator-() const {
MInt res;
res.x = norm(P - x);
return res;
}
MInt inv() const {
assert(x != 0);
return power(*this, P - 2);
}
MInt &operator*=(const MInt &rhs) {
x = 1LL * x * rhs.x % P;
return *this;
}
MInt &operator+=(const MInt &rhs) {
x = norm(x + rhs.x);
return *this;
}
MInt &operator-=(const MInt &rhs) {
x = norm(x - rhs.x);
return *this;
}
MInt &operator/=(const MInt &rhs) {
return *this *= rhs.inv();
}
friend MInt operator*(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res *= rhs;
return res;
}
friend MInt operator+(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res += rhs;
return res;
}
friend MInt operator-(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res -= rhs;
return res;
}
friend MInt operator/(const MInt &lhs, const MInt &rhs) {
MInt res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, MInt &a) {
ll v;
is >> v;
a = MInt(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const MInt &a) {
return os << a.val();
}
};
constexpr int P = 1000000007;
using Z = MInt<P>;
#define ll Z
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
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 = {array<ll, 2>{0, 1}};
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];
return {res};
}
jz ksm (jz a, ll b) {
jz res{array<ll, 2>{1, 0}, array<ll, 2>{0, 1}};
while (b.x) {
if (b.x & 1) res = res * a;
a = a * a;
b.x >>= 1;
}
return res;
}
struct Solver {
void solve() {
cin >> n >> m >> k;
A[1][0] = k - 1;
A[1][1] = k - 2;
if (k.x <= 1) return cout << "0\n", void();
// if (k == 2) {
// if (m == 3) cout << "0\n";
// else cout << 2 << '\n';
// return;
// }
auto p = ksm({A}, m-1);
ll y = p.a[1][0];
// cout << "x: " << x << '\n';
// cout << "y: " << y << '\n';
ll ans = (y * k) * power(((k-1)*(k-1)-k+2), (n.x-1ll)*m.x);
cout << ans << '\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.x--) {
Solver solver;
solver.solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3232kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3484kb
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