結果
| 問題 | No.2156 ぞい文字列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-16 23:40:12 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,243 bytes |
| 記録 | |
| コンパイル時間 | 3,246 ms |
| コンパイル使用メモリ | 282,920 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-28 23:50:51 |
| 合計ジャッジ時間 | 4,315 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace atcoder;
using namespace std;
using mint = modint998244353;
template <typename T>
struct mat {
vector<vector<T>> M;
int H = 0, W = 0;
mat(int h, int w) {
this->H = h;
this->W = w;
M = vector<vector<T>>(h, vector<T>(w));
}
mat(vector<vector<T>> &v) {
this->H = v.size();
this->W = v[0].size();
M = v;
}
vector<T> operator[](int i) const { return M[i]; }
vector<T> &operator[](int i) { return M[i]; }
mat operator*(const mat &a) {
mat res(H, a.W);
rep(i, H) rep(k, W) rep(j, a.W) res[i][j] += M[i][k] * a[k][j];
return res;
}
mat pow(ll n) {
mat res(H, W);
rep(i, H) res[i][i] = 1;
mat a = *this;
while (n) {
if (n & 1) res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
ll N;
cin >> N;
vector<vector<mint>> A = {{1, 1}, {1, 0}};
mat<mint> a(A);
mat<mint> b = a.pow(N);
cout << (b[0][0] - 1).val() << "\n";
return 0;
}