QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102942#5661. Multi-LaddersJolerAC ✓0ms3408kbC++201.7kb2023-05-03 20:25:202023-05-03 20:25:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 20:25:22]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3408kb
  • [2023-05-03 20:25:20]
  • 提交

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, m * (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();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3232kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 0ms
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