結果
| 問題 | No.3515 Anti EIKO |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-25 15:02:43 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| コード長 | 1,606 bytes |
| 記録 | |
| コンパイル時間 | 1,696 ms |
| コンパイル使用メモリ | 218,924 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-25 15:02:52 |
| 合計ジャッジ時間 | 3,805 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];
ll k;
inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
struct mtx {
vector<vector<ll> > a;
int n, m;
mtx(int _n, int _m) {
n = _n, m = _m;
a = vector<vector<ll> >(n + 1, vector<ll>(m + 1));
}
mtx operator*(const mtx& w) const {
mtx res(n, m);
res.n = n, res.m = w.m;
for (int k = 1; k < m + 1; k++)
for (int i = 1; i < n + 1; i++)
for (int j = 1; j < w.m + 1; j++)
res.a[i][j] = (res.a[i][j] + a[i][k] * w.a[k][j]) % MOD;
return res;
}
};
mtx cal(mtx st, mtx x, ll k) {
mtx res = st;
while (k) {
if (k & 1) {
res = x * res;
}
k >>= 1;
x = x * x;
}
return res;
}
void solve() {
scanf("%d%lld", &n, &k);
n <<= 2;
n++;
mtx x(n, 1);
x.a[1][1] = 1;
mtx f(n, n);
for (int i = 1; i < n; i++) {
if (i % 4 == 1) f.a[1][i] = 4 * qmi(5, MOD - 2, MOD) % MOD;
else f.a[1][i] = 3 * qmi(5, MOD - 2, MOD) % MOD;
}
for (int i = 1; i < n; i++)
if (i % 4 != 1)
f.a[2][i] = qmi(5, MOD - 2, MOD);
for (int i = 2; i <= n; i++) f.a[i][i - 1] = qmi(5, MOD - 2, MOD) % MOD;
auto u = cal(x, f, k);
printf("%lld\n", u.a[n][1]);
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) solve();
return 0;
}