結果
問題 | No.2883 K-powered Sum of Fibonacci |
ユーザー | shobonvip |
提出日時 | 2024-09-20 02:31:04 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 3,000 ms |
コード長 | 2,195 bytes |
コンパイル時間 | 3,740 ms |
コンパイル使用メモリ | 248,136 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 02:31:10 |
合計ジャッジ時間 | 5,117 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 3 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 3 ms
5,376 KB |
testcase_29 | AC | 3 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 3 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 3 ms
5,376 KB |
コンパイルメッセージ
main.cpp:6:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 6 | bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; } | ^~~~ main.cpp:6:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 6 | bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; } | ^~~~ main.cpp:7:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 7 | bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; } | ^~~~ main.cpp:7:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 7 | bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; } | ^~~~
ソースコード
#include<bits/stdc++.h> #define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define all(v) begin(v),end(v) using namespace std; using ll = long long; bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; } bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; } #include<atcoder/modint> #include<atcoder/convolution> using namespace atcoder; typedef atcoder::modint998244353 mint; vector<mint> BerlekampMassey(const vector<mint> &s) { const int N = (int)s.size(); vector<mint> b, c; b.reserve(N + 1); c.reserve(N + 1); b.push_back(mint(1)); c.push_back(mint(1)); mint y = mint(1); for (int ed = 1; ed <= N; ed++) { int l = int(c.size()), m = int(b.size()); mint x = 0; for (int i = 0; i < l; i++) x += c[i] * s[ed - l + i]; b.emplace_back(mint(0)); m++; if (x == mint(0)) continue; mint freq = x / y; if (l < m) { auto tmp = c; c.insert(begin(c), m - l, mint(0)); for (int i = 0; i < m; i++) c[m - 1 - i] -= freq * b[m - 1 - i]; b = tmp; y = x; } else { for (int i = 0; i < m; i++) c[l - 1 - i] -= freq * b[m - 1 - i]; } } reverse(begin(c), end(c)); return c; } mint bostan_mori(ll n, vector<mint> p, vector<mint> q){ assert(p.size() < q.size()); while (n > 0){ vector<mint> qi((int)q.size()); for (int i=0; i<(int)q.size(); i++){ if (i%2==0) qi[i] = q[i]; else qi[i] = -q[i]; } vector<mint> qq = convolution<mint>(q, qi); q.resize(((int)qq.size()+1)/2); for (int i=0; i<((int)qq.size()+1)/2; i++){ q[i] = qq[2*i]; } vector<mint> pp = convolution<mint>(p, qi); if (n%2==0){ p.resize(((int)pp.size()+1)/2); for (int i=0; i<((int)pp.size()+1)/2; i++){ p[i] = pp[2*i]; } }else{ p.resize((int)pp.size()/2); for (int i=0; i<(int)pp.size()/2; i++){ p[i] = pp[2*i+1]; } } n/=2; } return p[0]*q[0].inv(); } int main(){ cin.tie(0)->sync_with_stdio(0); ll n, k; cin >> n >> k; vector<mint> f(300); f[1] = 1; rep(i,2,300){ f[i] = f[i-1] + f[i-2]; } rep(i,0,300){ f[i] = f[i].pow(k); } rep(i,1,300){ f[i] += f[i-1]; } vector<mint> g = BerlekampMassey(f); f = convolution(f,g); f.resize((int)g.size()-1); cout << bostan_mori(n,f,g).val() << '\n'; }