結果
問題 | No.1073 無限すごろく |
ユーザー |
![]() |
提出日時 | 2020-06-06 03:57:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 3,572 ms |
コンパイル使用メモリ | 229,960 KB |
最終ジャッジ日時 | 2025-01-10 23:13:47 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #include <bits/stdc++.h> using namespace std; #define MOD 1000000007 vector<vector<ll>> matrixmul(ll m,vector<vector<ll>> a,vector<vector<ll>> b){ vector<vector<ll>> c(m,vector<ll>(m,0)); rep(i,m){ rep(j,m){ rep(k,m) c[i][j]=(c[i][j]+a[i][k]*b[k][j]%MOD)%MOD; } } return c; } vector<vector<ll>> matrixpow(ll m,vector<vector<ll>> vec,ll n){ vector<vector<ll>> ans(m,vector<ll>(m,0)); rep(i,m) ans[i][i]=1; while(n){ if(n&1) ans=matrixmul(m,ans,vec); vec=matrixmul(m,vec,vec); n>>=1; } return ans; } int main(){ ll n; cin>>n; vector<vector<ll>> mat(6,vector<ll>(6)); rep(i,6) mat[0][i]=166666668; rep(i,5) mat[i+1][i]=1; vector<vector<ll>> pmat=matrixpow(6,mat,n); cout<<pmat[0][0]<<endl; return 0; }