結果
| 問題 |
No.2156 ぞい文字列
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-12-09 21:35:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,182 bytes |
| コンパイル時間 | 1,578 ms |
| コンパイル使用メモリ | 173,584 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 20:47:44 |
| 合計ジャッジ時間 | 2,248 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL <<62), MOD = 998244353;
constexpr int INF = (1<<30);
template <typename T>
vector<vector<T>> MatrixProduct(vector<vector<T>> vec1, vector<vector<T>> vec2){
int N = vec1.size(), M = vec2[0].size(), L = vec2.size();
vector<vector<T>> res(N,vector<T>(M,0));
rep(i,N) rep(j,M) rep(k,L) res[i][j] = (res[i][j] + vec1[i][k] * vec2[k][j]) % MOD;
return res;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<vector<ll>> a(1,vector<ll>(2,0)), t(2,vector<ll>(2,0));
a[0][0] = t[0][0] = t[0][1] = t[1][0] = 1;
while(n){
if(n&1) a = MatrixProduct(t,a);
t = MatrixProduct(t,t);
n >>= 1;
}
cout << (a[0][0]+a[0][1]-1+MOD) % MOD << '\n';
return 0;
}
houren