結果
問題 | No.2156 ぞい文字列 |
ユーザー | take000 |
提出日時 | 2022-12-09 22:27:38 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 845 bytes |
コンパイル時間 | 4,099 ms |
コンパイル使用メモリ | 260,524 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 22:25:58 |
合計ジャッジ時間 | 5,219 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; struct Matrix { mint mat[2][2]; }; Matrix mul(Matrix a, Matrix b) { Matrix c; rep(i, 2) rep(j, 2) { c.mat[i][j] = 0; rep(k, 2) c.mat[i][j] += a.mat[i][k] * b.mat[k][j]; } return c; } Matrix pow(Matrix a, ll n) { if (n == 1) return a; Matrix res; if (n % 2 == 0) { res = pow(a, n / 2); return mul(res, res); } else { res = pow(a, n - 1); return mul(res, a); } } int main() { cin.tie(0)->sync_with_stdio(0); ll N; cin >> N; Matrix A = {{{1, 1}, {1, 0}}}; Matrix B = pow(A, N); cout << (B.mat[0][0] - 1).val() << "\n"; return 0; }