QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768964 | #8049. Equal Sums | AllHailLelouch | WA | 0ms | 3588kb | C++14 | 994b | 2024-11-21 15:28:29 | 2024-11-21 15:28:29 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int P = 998244353;
typedef std::array<std::array<i64, 3>, 3> Matrix;
Matrix operator *(const Matrix &a, Matrix &b) {
Matrix c{0, 0, 0, 0, 0, 0, 0, 0, 0};
for (auto k : {0, 1, 2}) {
for (auto i : {0, 1, 2}) {
for (auto j : {0, 1, 2}) {
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % P;
}
}
}
return c;
}
int main() {
std::cin.tie(nullptr) -> sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
Matrix I{1, 0, 0, 0, 1, 0, 0, 0, 1};
Matrix B{0, 1, 1, 1, 0, 0, 0, 1, 0};
for (int k = n; k; k /= 2, B = B * B) if (k & 1) I = I * B;
int Z = (I[0][0] + I[1][1] + I[2][2]);
std::unordered_map<int, i64> dp;
auto f = [&](auto self, int x) -> int {
if (x <= 1) return x ? Z : 1;
if (dp.count(x)) return dp[x];
if (x & 1) return dp[x] = Z * self(self, x / 2) % P;
return dp[x] = (self(self, x / 2), self(self, x / 2 - 1)) % P;
};
std::cout << f(f, m);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
2 3 1 2 2 3 1 4 2 2 1 3
output:
4
result:
wrong answer 1st numbers differ - expected: '2', found: '4'