QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533029#5661. Multi-Laddersttbchimbu999#AC ✓1ms3592kbC++141.7kb2024-08-25 16:06:022024-08-25 16:06:04

Judging History

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

  • [2024-08-25 16:06:04]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3592kb
  • [2024-08-25 16:06:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define matrix vector<vector<int> >
const int M = 1e9 + 7;
matrix operator *(const matrix &a, const matrix &b) {
	matrix c;
	c.resize(a.size());
	for (int i = 0; i < (int)a.size(); ++i) {
		c[i].resize(b[0].size(), 0);
		for (int j = 0; j < (int)b[0].size(); ++j) {
			for (int z = 0; z < (int)a[0].size(); ++z) {
				c[i][j] = (c[i][j] + 1LL * a[i][z] * b[z][j]) % M;
			}
		}
	}
	return c;
}
matrix unit(int n) {
	matrix ans(n, vector<int>(n, 0));
	for (int i = 0; i < n; ++i) {
		ans[i][i] = 1;
	}
	return ans;
}
matrix fpow(matrix a, long long b, int M = ::M) {
	matrix ans = unit(a.size());
	while (b) {
		if (b & 1) ans = ans * a;
		b >>= 1;
		a = a * a;
	}
	return ans;
}
int fpow(int a, long long b, int M = ::M) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = 1LL * ans * a % M;
		a = 1LL * a * a % M;
		b >>= 1;
	}
	return ans;
}
void solve() {
	int n, k, l;
	cin >> n >> k >> l;
	matrix f = {{1LL * l * (l - 1) % M, 0LL, 1LL * l * (l - 1) % M * (l - 2) % M, 1LL * l * (l - 1) % M}};
	matrix m = {
		{0, 0, 0, 0},
		{0, 0, 0, 0},
		{1, 0, l - 2, 1},
		{0, 1, l - 1, 0}
	};
	int ans = (f * fpow(m, k - 3 + 1))[0][0];
	int tmp = fpow((1LL * (l - 1) * (l - 1) - l + 2) % M, 1LL * (n - 1) * k);
	ans = 1LL * ans * tmp % M;
	cout << ans << '\n';
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef LOCAL
	    // freopen("TEST.inp", "r", stdin);
	    // freopen("TEST.out", "w", stdout);
    #else
    	// freopen("TEST.inp", "r", stdin);
    	// freopen("TEST.out", "w", stdout);
    #endif
	int L;
	cin >> L;
	while (L--) {
		solve();
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

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