結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー |
![]() |
提出日時 | 2020-08-17 14:16:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,252 ms / 2,000 ms |
コード長 | 3,422 bytes |
コンパイル時間 | 2,033 ms |
コンパイル使用メモリ | 130,968 KB |
最終ジャッジ日時 | 2025-01-13 02:31:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 |
コンパイルメッセージ
main.cpp: In function ‘void get(std::vector<long long int>&)’: main.cpp:25:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | void get(vll &a){re(i,a.size()) scanf("%lld",&a[i]);} | ~~~~~^~~~~~~~~~~~~~ main.cpp: In function ‘void get(std::vector<std::vector<long long int> >&)’: main.cpp:26:56: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | void get(vvl &a){re(i,a.size()) re(j,a[0].size()) scanf("%lld",&a[i][j]);} | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #define vll vector<ll> #define vvvl vector<vvl> #define vvl vector<vector<ll>> #define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c)) #define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c<b;c++) #define rep(a,b,c) for(ll a=b;a<c;a++) #define all(obj) (obj).begin(), (obj).end() typedef long long int ll; typedef long double ld; using namespace std; void get(vll &a){re(i,a.size()) scanf("%lld",&a[i]);} void get(vvl &a){re(i,a.size()) re(j,a[0].size()) scanf("%lld",&a[i][j]);} void print(vll &a){re(i,a.size()) cout<<a[i]<<(i==a.size()-1?"\n":" ");} void print(vvl &a){re(i,a.size()) re(j,a[0].size())cout<<a[i][j]<<(j==a[0].size()-1?"\n":" ");} // matrix<集合> (集合, 加法における単位元, 加算, 乗算) template<typename T> struct matrix{ function<T(T, T)> f, g; vector<vector<T>> mat; T unit; matrix(vector<vector<T>> v, T UNIT, function<T(T, T)> add_func, function<T(T, T)> multi_func):f(add_func), g(multi_func), unit(UNIT){ mat = v; } matrix<T> t(){ vector<vector<T>> ret(mat[0].size(), vector<T>(mat.size())); re(i, mat[0].size()) re(j, mat.size()) ret[i][j] = mat[j][i]; return matrix<T>(ret, f, g); } matrix<T> operator * (matrix<T> B){ vector<vector<T>> ret(mat.size(), vector<T>(B.mat[0].size(), unit)); if(mat[0].size()!=B.mat.size()){ std::cout << "matrix operator " << "*" << " error" << '\n'; return matrix<T>(ret, unit, f, g); } re(i, mat.size()){ re(j, B.mat[0].size()){ re(k, mat[0].size()){ ret[i][j] = f(ret[i][j], g(mat[i][k], B.mat[k][j])); } } } return matrix<T>(ret, unit, f, g); } matrix<T> operator * (ll num){ vector<vector<T>> ret = mat; re(i, mat.size()) re(j, mat[0].size()) ret[i][j] *= num; return matrix<T>(ret, unit, f, g); } matrix<T> operator + (matrix<T> B){ vector<vector<T>> ret = mat; if(mat.size()!=B.mat.size()||mat[0].size()!=B.mat[0].size()){ std::cout << "matrix operator " << "+" << " error" << '\n'; return matrix<T>(ret, unit, f, g); } re(i, mat.size()) re(j, mat[0].size()) ret[i][j] = f(mat[i][j], B.mat[i][j]); return matrix<T>(ret, unit, f, g); } matrix<T> operator ^ (ll num){ matrix<T> ret(vector<vector<T>> (0, vector<T>(0)), unit, f, g); if(mat.size()!=mat[0].size()){ std::cout << "matrix operator " << "^" << " error" << '\n'; return ret; } matrix<T> tmp(mat, unit, f, g); bool flag = false; while(num>0){ if(num%2){ if(flag) ret = ret * tmp; else ret.mat = tmp.mat, flag = true; } num/=2, tmp = tmp * tmp; } return ret; } vector<T> & operator [](int n){ return mat[n]; } }; #define P 17 ll ad(ll a, ll b){return (a+b)%P;} ll ml(ll a, ll b){return (a*b)%P;} int main() { matrix<ll> A({{1},{0},{0},{0}}, 0, ad, ml); matrix<ll> B({{1, 1, 1, 1}, {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}}, 0, ad, ml); ll q;std::cin >> q; re(i, q){ ll t;std::cin >> t; if(t<=3) std::cout << 0 << '\n'; if(t==4) std::cout << 1 << '\n'; if(t>4){ matrix<ll> C = (B^(t-4))*A; std::cout << C[0][0] << '\n'; } } }