QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#519644 | #5661. Multi-Ladders | ucup-team1198# | WA | 0ms | 3704kb | C++20 | 2.2kb | 2024-08-14 22:38:44 | 2024-08-14 22:38:45 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MOD = 998244353;
int add(int a, int b) {
if (a + b < MOD)
return a + b;
return a + b - MOD;
}
int sub(int a, int b) {
if (a >= b)
return a - b;
return a + MOD - b;
}
int mul(int a, int b) {
return a * 1ll * b % MOD;
}
int pw(int a, long long n) {
int ans = 1;
while (n) {
if (n & 1ll)
ans = mul(ans, a);
n >>= 1;
a = mul(a, a);
}
return ans;
}
struct Matrix {
int vals[2][2];
Matrix() {
for (int i = 0; i < 2; ++i)
fill(vals[i], vals[i] + 2, 0);
}
Matrix(int kek[2][2]) {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j)
vals[i][j] = kek[i][j];
}
}
};
int tmp[2][2];
Matrix operator*(const Matrix& a, const Matrix& b) {
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
tmp[i][j] = 0;
}
}
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k)
tmp[i][k] = add(tmp[i][k], mul(a.vals[i][j], b.vals[j][k]));
}
}
return Matrix(tmp);
}
Matrix pw(Matrix a, long long n) {
Matrix ans;
ans.vals[0][0] = 1;
ans.vals[1][1] = 1;
while (n) {
if (n & 1ll) {
ans = ans * a;
}
n >>= 1;
a = a * a;
}
return ans;
}
void solve() {
int n, k, l;
cin >> n >> k >> l;
if (l <= 1) {
cout << 0 << '\n';
return;
}
Matrix A;
A.vals[0][0] = 0;
A.vals[0][1] = 1;
A.vals[1][0] = l - 1;
A.vals[1][1] = l - 2;
Matrix kek = pw(A, k - 2);
int ans = mul(l, mul(kek.vals[1][1], l - 1));
ans = mul(ans, pw(sub(mul(l - 1, l - 1), l - 2), k * 1ll * (n - 1)));
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3704kb
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 609185602 297791896 700486831 679435186 644334865 547605728 388839885 786397222 422088081 737574972 393596411 0 0 734353631
result:
wrong answer 7th lines differ - expected: '349400141', found: '609185602'