結果

問題 No.2156 ぞい文字列
ユーザー chestnut_68chestnut_68
提出日時 2022-12-10 00:52:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,505 bytes
コンパイル時間 4,364 ms
コンパイル使用メモリ 233,036 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 23:31:40
合計ジャッジ時間 5,081 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep1(a)          for(int z = 0; z < a; z++)
#define rep2(i, a)       for(int i = 0; i < a; i++)
#define rep3(i, a, b)    for(int i = a; i < b; i++)
#define rep4(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int MOD=998244353;
const int64_t INF = 1LL<<60;
void YN(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
}
struct Matrix{
  int N;
  vector<vector<int64_t>> M;
  Matrix(int X){
    N=X;
    M.resize(X);
    rep(i,X)M[i].assign(X,0);
  }
  Matrix(int X,int64_t Z){
    N=X;
    M.resize(N);
    rep(i,X)M[i].assign(X,Z);
    if(Z==-1){
      rep(i,N){
        rep(j,N){
          M[i][j]=(i==j?1:0);
        }
      }
    }
  }
  Matrix(vector<vector<int64_t>> A){
    N=A.size();
    M.resize(N);
    rep(i,N){
      M[i].resize(N);
      rep(j,N){
        M[i][j]=A[i][j];
      }
    }
  }
  Matrix operator+(const Matrix &other){
    Matrix ret(N);
    rep(i,N){
      rep(j,N){
        ret.M[i][j]=M[i][j]+other.M[i][j];
      }
    }
    return ret;
  }
  
  Matrix operator-(const Matrix &other){
    Matrix ret(N);
    rep(i,N){
      rep(j,N){
        ret.M[i][j]=M[i][j]-other.M[i][j];
      }
    }
    return ret;
  }
  
  Matrix operator*(const Matrix &other){
    Matrix ret(N,0);
    rep(i,N){
      rep(j,N){
        rep(k,N){ 
          ret.M[i][j]+=M[i][k]*other.M[k][j];
        }
      }
    }
    return ret;
  }
  
  Matrix operator*(int64_t K){
    Matrix ret(N);
    rep(i,N){
      rep(j,N){
        rep(k,N){ 
          ret.M[i][j]=K*M[i][k];
        }
      }
    }
    return ret;
  }
  Matrix operator%(int64_t MOD){
    Matrix ret(N);
    rep(i,N){
      rep(j,N){
        ret.M[i][j]=M[i][j]%MOD;
      }
    }
    return ret;
  }
  Matrix pow(int64_t X){
    Matrix ret(N,-1),O(M);
    while(X>0){
      if(X&1)ret=O*ret;
      O=O*O;
      X>>=1;
    }
    return ret;
  }
  Matrix pow_mod(int64_t X,int64_t MOD){
    Matrix ret(N,-1),O(M);
    while(X>0){
      if(X&1)ret=O*ret%MOD;
      O=O*O%MOD;
      X>>=1;
    }
    return ret;
  }
  
  void print(){
    rep(i,N){
      rep(j,N){
        cout<<M[i][j]<<' ';
      }
      cout<<endl;
    }
  }
};
int main(){
	int64_t N;cin>>N;
	vector<vector<int64_t>> A={{1,1},{1,0}};
	Matrix M(A);
	auto X=M.pow_mod(N-1,MOD);
	cout<<(X.M[0][0]+X.M[1][0]-1+MOD)%MOD;
}
0