結果
| 問題 |
No.2156 ぞい文字列
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-05-05 15:04:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 995 bytes |
| コンパイル時間 | 951 ms |
| コンパイル使用メモリ | 111,420 KB |
| 最終ジャッジ日時 | 2025-02-12 17:11:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
using ll = long long;
const ll modc = 998244353;
vector<vector<ll>> dot(vector<vector<ll>> &a, vector<vector<ll>> &b){
vector<vector<ll>> c(2, vector<ll>(2));
for (int i=0; i<2; i++){
for (int k=0; k<2; k++){
for (int j=0; j<2; j++){
c[i][j] += (a[i][k] * b[k][j]) % modc;
c[i][j] %= modc;
}
}
}
return c;
}
int main(){
ll N;
cin >> N;
if (N == 2){
cout << 1 << endl;
return 0;
}
N -= 2;
vector<vector<ll>> A = {{1,1},{1,0}}, B={{1,0},{0,1}};
while(N){
if (N % 2 == 1) B = dot(A, B);
N >>= 1;
A = dot(A, A);
}
cout << (modc + B[0][0] * 2 + B[0][1] - 1) % modc << endl;
return 0;
}
srjywrdnprkt