結果
| 問題 | No.2156 ぞい文字列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-10 16:55:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 4,391 bytes |
| 記録 | |
| コンパイル時間 | 1,836 ms |
| コンパイル使用メモリ | 195,420 KB |
| 最終ジャッジ日時 | 2025-02-09 09:12:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
#include <atcoder/modint>
using mint = atcoder::modint998244353;
ostream &operator<<(ostream &os, const mint &p) { return os << p.val(); }
template <class T, size_t n, size_t m = n> struct static_matrix {
std::array<std::array<T, m>, n> A;
static_matrix() : A{{}} {}
static_matrix(T val) : A{{}} {
for (int i = 0; i < (int)n; i++) A[i].fill(val);
}
size_t size() const { return n; }
int row() const { return (int)n; }
int col() const { return (int)m; }
inline const std::array<T, m> &operator[](int i) const { return A[i]; } // read
inline std::array<T, m> &operator[](int i) { return A[i]; } // write
static static_matrix E() {
assert(n == m);
static_matrix ret;
for (int i = 0; i < (int)n; i++) ret[i][i] = T(1);
return ret;
}
static_matrix &operator+=(const static_matrix &B) {
int N = row(), M = col();
assert(N == B.row() && M == B.col());
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
(*this)[i][j] += B[i][j];
}
}
return (*this);
}
static_matrix &operator-=(const static_matrix &B) {
int N = row(), M = col();
assert(N == B.row() && M == B.col());
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
(*this)[i][j] -= B[i][j];
}
}
return (*this);
}
static_matrix &operator*=(const static_matrix &B) {
int N = row(), M = B.col(), L = B.row();
assert(L == col());
static_matrix C;
for (int i = 0; i < N; i++) {
for (int k = 0; k < L; k++) {
for (int j = 0; j < M; j++) {
C[i][j] += (*this)[i][k] * B[k][j];
}
}
}
A.swap(C.A);
return (*this);
}
static_matrix pow(long long k) {
assert(row() == col());
static_matrix B = static_matrix::E(), X = (*this);
while (k) {
if (k & 1) B *= X;
X *= X;
k >>= 1;
}
A.swap(B.A);
return (*this);
}
static_matrix operator+(const static_matrix &B) { return ((*this) += B); }
static_matrix operator-(const static_matrix &B) { return ((*this) -= B); }
static_matrix operator*(const static_matrix &B) { return ((*this) *= B); }
friend std::ostream &operator<<(std::ostream &os, static_matrix &A) {
int N = A.row(), M = A.col();
for (int i = 0; i < N; i++) {
os << '[';
for (int j = 0; j < M; j++) os << A[i][j] << " \n"[j == M - 1];
}
return (os);
}
static_matrix &operator+=(const T &k) {
int N = row(), M = col();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) (*this)[i][j] += k;
return (*this);
}
static_matrix &operator-=(const T &k) {
int N = row(), M = col();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) (*this)[i][j] -= k;
return (*this);
}
static_matrix &operator*=(const T &k) {
int N = row(), M = col();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) (*this)[i][j] *= k;
return (*this);
}
static_matrix &operator/=(const T &k) {
int N = row(), M = col();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++) (*this)[i][j] /= k;
return (*this);
}
static_matrix operator+(const T &k) { return ((*this) += k); }
static_matrix operator-(const T &k) { return ((*this) -= k); }
static_matrix operator*(const T &k) { return ((*this) *= k); }
static_matrix operator/(const T &k) { return ((*this) /= k); }
};
/**
* @brief Static Matrix (行列, サイズ固定)
* @docs docs/data_structure/static_matrix.md
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N;
cin >> N;
static_matrix<mint, 2, 2> dp;
dp[0][0] = dp[0][1] = dp[1][0] = 1;
dp = dp.pow(N - 1);
mint ans = dp[0][0] + dp[1][0] - 1;
cout << ans << '\n';
return 0;
}