結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | peroon |
提出日時 | 2019-04-26 20:57:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 612 ms / 2,000 ms |
コード長 | 1,659 bytes |
コンパイル時間 | 2,194 ms |
コンパイル使用メモリ | 174,024 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-16 12:12:35 |
合計ジャッジ時間 | 5,344 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 3 ms
4,376 KB |
testcase_04 | AC | 207 ms
4,376 KB |
testcase_05 | AC | 243 ms
4,376 KB |
testcase_06 | AC | 313 ms
4,376 KB |
testcase_07 | AC | 336 ms
4,380 KB |
testcase_08 | AC | 401 ms
4,380 KB |
testcase_09 | AC | 611 ms
4,376 KB |
testcase_10 | AC | 612 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using VV = vector<vector<ll> >; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<<endl #define p2(s, t) cout << (s) << " " << (t) << endl #define br() p("") #define pn(s) cout << (#s) << " " << (s) << endl #define p_yes() p("Yes") #define p_no() p("No") const ll mod = 17; const ll inf = 1e18; template < typename T > void vprint(T &V){ for(auto v : V){ cout << v << " "; } cout << endl; } // Matrix Library VV mat_mul(const VV& x, const VV& y){ int a = x.size(); int b = x[0].size(); int c = y[0].size(); VV z(a, vector<ll>(c, 0)); FOR(i, 0, a){ FOR(j, 0, c){ FOR(k, 0, b){ z[i][j] += x[i][k] * y[k][j]; z[i][j] %= mod; // 必要であれば } } } return z; } VV mat_pow(const VV& x, ll k){ int n = x.size(); VV y(n, vector<ll>(n, 0)); FOR(i, 0, n){ y[i][i] = 1; } VV z = x; if(k==0) return y; if(k==1) return z; if(k%2==0){ return mat_pow(mat_mul(x, x), k/2); }else{ return mat_mul(x, mat_pow(x, k-1)); } } void print_mat(VV x){ ll H = x.size(); FOR(i, 0, H){ vprint(x[i]); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll Q; cin >> Q; VV A ={ {1, 1, 1, 1}, {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, }; FOR(i, 0, Q){ ll n; cin >> n; auto B = mat_pow(A, n); ll ans = B[3][3]; p(ans); } return 0; }