結果
問題 |
No.3243 Multiplication 8 1
|
ユーザー |
![]() |
提出日時 | 2025-08-22 21:40:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,617 bytes |
コンパイル時間 | 3,093 ms |
コンパイル使用メモリ | 293,016 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-22 21:40:11 |
合計ジャッジ時間 | 3,929 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; using mint = modint998244353; using ll = long long; #define fix(x) fixed << setprecision(x) #define rep(i, n) for(int i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;} constexpr ll INFLL = (1LL << 62), MOD = 998244353; constexpr int INF = (1 << 30); template <typename T> vector<vector<T>> MatrixMul(vector<vector<T>> V1, vector<vector<T>> V2, T e){ assert(V1[0].size()==V2.size()); int N = V1.size(), M = V2[0].size(), L = V2.size(); vector<vector<T>> res(N,vector<T>(M,e)); rep(i,N) rep(j,M) rep(k,L) res[i][j] += V1[i][k] * V2[k][j]; return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); vector<vector<mint>> b(7,vector<mint>(7,0)), y(7,vector<mint>(1,0)); y[0][0] = 1; map<int,int> mp; mp[1] = 0, mp[2] = 1, mp[4] = 2, mp[8] = 0; mp[-1] = 3, mp[-2] = 4, mp[-4] = 5, mp[-8] = 6; for(int x:{1,-1,2,-2,4,-4,-8}){ for(int y:{1,2,-1,-2}){ if(!mp.count(x*y)) continue; b[mp[x]][mp[x*y]] = 1; } } int t; cin >> t; while(t--){ ll n; cin >> n; mint z = mint(2).pow(n-1); auto x = y; auto a = b; while(n){ if(n&1) x = MatrixMul(a,x,mint(0)); a = MatrixMul(a,a,mint(0)); n >>= 1; } cout << (x[0][0]-z).val() << '\n'; } return 0; }