結果
問題 | No.2413 Multiple of 99 |
ユーザー | 蜜蜂 |
提出日時 | 2023-08-11 23:49:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,939 ms / 8,000 ms |
コード長 | 11,669 bytes |
コンパイル時間 | 4,889 ms |
コンパイル使用メモリ | 258,732 KB |
実行使用メモリ | 67,080 KB |
最終ジャッジ日時 | 2024-11-18 19:37:49 |
合計ジャッジ時間 | 42,617 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
18,864 KB |
testcase_01 | AC | 113 ms
19,016 KB |
testcase_02 | AC | 313 ms
18,848 KB |
testcase_03 | AC | 107 ms
19,044 KB |
testcase_04 | AC | 425 ms
19,520 KB |
testcase_05 | AC | 470 ms
20,432 KB |
testcase_06 | AC | 451 ms
20,244 KB |
testcase_07 | AC | 2,867 ms
66,956 KB |
testcase_08 | AC | 397 ms
19,012 KB |
testcase_09 | AC | 2,587 ms
66,952 KB |
testcase_10 | AC | 2,819 ms
66,828 KB |
testcase_11 | AC | 2,939 ms
66,948 KB |
testcase_12 | AC | 2,858 ms
67,080 KB |
testcase_13 | AC | 2,856 ms
66,952 KB |
testcase_14 | AC | 2,861 ms
66,948 KB |
testcase_15 | AC | 2,927 ms
66,956 KB |
testcase_16 | AC | 1,614 ms
43,260 KB |
testcase_17 | AC | 1,568 ms
42,172 KB |
testcase_18 | AC | 2,896 ms
64,628 KB |
testcase_19 | AC | 649 ms
23,468 KB |
testcase_20 | AC | 496 ms
21,320 KB |
testcase_21 | AC | 668 ms
23,604 KB |
testcase_22 | AC | 2,849 ms
65,060 KB |
testcase_23 | AC | 649 ms
24,648 KB |
コンパイルメッセージ
main.cpp: In member function 'FormalPowerSeries<T>::F& FormalPowerSeries<T>::multiply_inplace(std::vector<std::pair<int, E> >)': main.cpp:152:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 152 | auto [d, c] = g.front(); | ^ main.cpp:157:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 157 | for (auto &[j, b] : g) { | ^ main.cpp: In member function 'FormalPowerSeries<T>::F& FormalPowerSeries<T>::divide_inplace(std::vector<std::pair<int, E> >)': main.cpp:168:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 168 | auto [d, c] = g.front(); | ^ main.cpp:173:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 173 | for (auto &[j, b] : g) { | ^
ソースコード
//g++ 1.cpp -std=c++17 -O2 -I . #include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; using vvld = vector<vld>; using vst = vector<string>; using vvst = vector<vst>; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue<T,vector<T>,less<T>> #define pq_small(T) priority_queue<T,vector<T>,greater<T>> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) template<class T> struct FormalPowerSeries : vector<T> { using vector<T>::vector; using vector<T>::operator=; using F = FormalPowerSeries; F operator-() const { F res(*this); for (auto &e : res) e = -e; return res; } F &operator*=(const T &g) { for (auto &e : *this) e *= g; return *this; } F &operator/=(const T &g) { assert(g != T(0)); *this *= g.inv(); return *this; } F &operator+=(const F &g) { int n = this->size(), m = g.size(); rep(i,0, min(n, m)) (*this)[i] += g[i]; return *this; } F &operator-=(const F &g) { int n = this->size(), m = g.size(); rep(i,0, min(n, m)) (*this)[i] -= g[i]; return *this; } F &operator<<=(const int d) { int n = this->size(); if (d >= n) *this = F(n); this->insert(this->begin(), d, 0); this->resize(n); return *this; } F &operator>>=(const int d) { int n = this->size(); this->erase(this->begin(), this->begin() + min(n, d)); this->resize(n); return *this; } // O(n log n) F inv(int d = -1) const { int n = this->size(); assert(n != 0 && (*this)[0] != 0); if (d == -1) d = n; assert(d >= 0); F res{(*this)[0].inv()}; for (int m = 1; m < d; m *= 2) { F f(this->begin(), this->begin() + min(n, 2*m)); F g(res); f.resize(2*m), internal::butterfly(f); g.resize(2*m), internal::butterfly(g); rep(i,0, 2*m) f[i] *= g[i]; internal::butterfly_inv(f); f.erase(f.begin(), f.begin() + m); f.resize(2*m), internal::butterfly(f); rep(i,0, 2*m) f[i] *= g[i]; internal::butterfly_inv(f); T iz = T(2*m).inv(); iz *= -iz; rep(i,0, m) f[i] *= iz; res.insert(res.end(), f.begin(), f.begin() + m); } res.resize(d); return res; } // fast: FMT-friendly modulus only // O(n log n) F &multiply_inplace(const F &g, int d = -1) { int n = this->size(); if (d == -1) d = n; assert(d >= 0); *this = convolution(move(*this), g); this->resize(d); return *this; } F multiply(const F &g, const int d = -1) const { return F(*this).multiply_inplace(g, d); } // O(n log n) F ÷_inplace(const F &g, int d = -1) { int n = this->size(); if (d == -1) d = n; assert(d >= 0); *this = convolution(move(*this), g.inv(d)); this->resize(d); return *this; } F divide(const F &g, const int d = -1) const { return F(*this).divide_inplace(g, d); } // // naive // // O(n^2) // F &multiply_inplace(const F &g) { // int n = this->size(), m = g.size(); // drep(i, n) { // (*this)[i] *= g[0]; // rep2(j, 1, min(i+1, m)) (*this)[i] += (*this)[i-j] * g[j]; // } // return *this; // } // F multiply(const F &g) const { return F(*this).multiply_inplace(g); } // // O(n^2) // F ÷_inplace(const F &g) { // assert(g[0] != T(0)); // T ig0 = g[0].inv(); // int n = this->size(), m = g.size(); // rep(i, n) { // rep2(j, 1, min(i+1, m)) (*this)[i] -= (*this)[i-j] * g[j]; // (*this)[i] *= ig0; // } // return *this; // } // F divide(const F &g) const { return F(*this).divide_inplace(g); } // sparse // O(nk) F &multiply_inplace(vector<pair<int, T>> g) { int n = this->size(); auto [d, c] = g.front(); if (d == 0) g.erase(g.begin()); else c = 0; per(i, n-1, 0) { (*this)[i] *= c; for (auto &[j, b] : g) { if (j > i) break; (*this)[i] += (*this)[i-j] * b; } } return *this; } F multiply(const vector<pair<int, T>> &g) const { return F(*this).multiply_inplace(g); } // O(nk) F ÷_inplace(vector<pair<int, T>> g) { int n = this->size(); auto [d, c] = g.front(); assert(d == 0 && c != T(0)); T ic = c.inv(); g.erase(g.begin()); rep(i,0, n) { for (auto &[j, b] : g) { if (j > i) break; (*this)[i] -= (*this)[i-j] * b; } (*this)[i] *= ic; } return *this; } F divide(const vector<pair<int, T>> &g) const { return F(*this).divide_inplace(g); } // multiply and divide (1 + cz^d) // O(n) void multiply_inplace(const int d, const T c) { int n = this->size(); if (c == T(1)) per(i, n-d-1,0) (*this)[i+d] += (*this)[i]; else if (c == T(-1)) per(i, n-d-1,0) (*this)[i+d] -= (*this)[i]; else per(i, n-d-1, 0) (*this)[i+d] += (*this)[i] * c; } // O(n) void divide_inplace(const int d, const T c) { int n = this->size(); if (c == T(1)) rep(i,0, n-d) (*this)[i+d] -= (*this)[i]; else if (c == T(-1)) rep(i,0, n-d) (*this)[i+d] += (*this)[i]; else rep(i,0, n-d) (*this)[i+d] -= (*this)[i] * c; } // O(n) T eval(const T &a) const { T x(1), res(0); for (auto e : *this) res += e * x, x *= a; return res; } // O(n) F &integ_inplace() { int n = this->size(); assert(n > 0); if (n == 1) return *this = F{0}; this->insert(this->begin(), 0); this->pop_back(); vector<T> inv(n); inv[1] = 1; int p = T::mod(); rep(i, 2, n) inv[i] = - inv[p%i] * (p/i); rep(i, 2, n) (*this)[i] *= inv[i]; return *this; } F integ() const { return F(*this).integ_inplace(); } // O(n) F &deriv_inplace() { int n = this->size(); assert(n > 0); rep(i, 2, n) (*this)[i] *= i; this->erase(this->begin()); this->push_back(0); return *this; } F deriv() const { return F(*this).deriv_inplace(); } // O(n log n) F &log_inplace(int d = -1) { int n = this->size(); assert(n > 0 && (*this)[0] == 1); if (d == -1) d = n; assert(d >= 0); if (d < n) this->resize(d); F f_inv = this->inv(); this->deriv_inplace(); this->multiply_inplace(f_inv); this->integ_inplace(); return *this; } F log(const int d = -1) const { return F(*this).log_inplace(d); } // O(n log n) // https://arxiv.org/abs/1301.5804 (Figure 1, right) F &exp_inplace(int d = -1) { int n = this->size(); assert(n > 0 && (*this)[0] == 0); if (d == -1) d = n; assert(d >= 0); F g{1}, g_fft{1, 1}; (*this)[0] = 1; this->resize(d); F h_drv(this->deriv()); for (int m = 2; m < d; m *= 2) { // prepare F f_fft(this->begin(), this->begin() + m); f_fft.resize(2*m), internal::butterfly(f_fft); // Step 2.a' { F f(m); rep(i,0, m) f[i] = f_fft[i] * g_fft[i]; internal::butterfly_inv(f); f.erase(f.begin(), f.begin() + m/2); f.resize(m), internal::butterfly(f); rep(i,0, m) f[i] *= g_fft[i]; internal::butterfly_inv(f); f.resize(m/2); f /= T(-m) * m; g.insert(g.end(), f.begin(), f.begin() + m/2); } // Step 2.b'--d' F t(this->begin(), this->begin() + m); t.deriv_inplace(); { // Step 2.b' F r{h_drv.begin(), h_drv.begin() + m-1}; // Step 2.c' r.resize(m); internal::butterfly(r); rep(i,0, m) r[i] *= f_fft[i]; internal::butterfly_inv(r); r /= -m; // Step 2.d' t += r; t.insert(t.begin(), t.back()); t.pop_back(); } // Step 2.e' if (2*m < d) { t.resize(2*m); internal::butterfly(t); g_fft = g; g_fft.resize(2*m); internal::butterfly(g_fft); rep(i,0, 2*m) t[i] *= g_fft[i]; internal::butterfly_inv(t); t.resize(m); t /= 2*m; } else { // この場合分けをしても数パーセントしか速くならない F g1(g.begin() + m/2, g.end()); F s1(t.begin() + m/2, t.end()); t.resize(m/2); g1.resize(m), internal::butterfly(g1); t.resize(m), internal::butterfly(t); s1.resize(m), internal::butterfly(s1); rep(i,0, m) s1[i] = g_fft[i] * s1[i] + g1[i] * t[i]; rep(i,0, m) t[i] *= g_fft[i]; internal::butterfly_inv(t); internal::butterfly_inv(s1); rep(i,0, m/2) t[i+m/2] += s1[i]; t /= m; } // Step 2.f' F v(this->begin() + m, this->begin() + min<int>(d, 2*m)); v.resize(m); t.insert(t.begin(), m-1, 0); t.push_back(0); t.integ_inplace(); rep(i,0, m) v[i] -= t[m+i]; // Step 2.g' v.resize(2*m); internal::butterfly(v); rep(i,0, 2*m) v[i] *= f_fft[i]; internal::butterfly_inv(v); v.resize(m); v /= 2*m; // Step 2.h' rep(i,0, min(d-m, m)) (*this)[m+i] = v[i]; } return *this; } F exp(const int d = -1) const { return F(*this).exp_inplace(d); } // O(n log n) F &pow_inplace(ll k, int d = -1) { int n = this->size(); if (d == -1) d = n; assert(d >= 0 && k >= 0); if (k == 0) { *this = F(d); if (d > 0) (*this)[0] = 1; return *this; } int l = 0; while (l < n && (*this)[l] == 0) ++l; if (l > (d-1)/k || l == n) return *this = F(d); T c = (*this)[l]; this->erase(this->begin(), this->begin() + l); *this /= c; this->log_inplace(d - l*k); *this *= k; this->exp_inplace(); *this *= c.pow(k); this->insert(this->begin(), l*k, 0); return *this; } F pow(const ll k, const int d = -1) const { return F(*this).pow_inplace(k, d); } F operator*(const T &g) const { return F(*this) *= g; } F operator/(const T &g) const { return F(*this) /= g; } F operator+(const F &g) const { return F(*this) += g; } F operator-(const F &g) const { return F(*this) -= g; } F operator<<(const int d) const { return F(*this) <<= d; } F operator>>(const int d) const { return F(*this) >>= d; } }; constexpr ll mod = 998244353; using mint = modint998244353; using fps = FormalPowerSeries<mint>; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,k;cin>>n>>k; int even=n/2; fps fp(10*n,0); // x^0 + x^1 + ... + x^9 rep(i,0,10)fp[i]=1; fps fpeven=fp.pow_inplace(even); fps fpodd=fpeven; if(n%2==1){ fps fp2(10,1); fpodd=convolution(fpodd,fp2); } /*rep(i,0,fpeven.size())cout<<fpeven[i].val()<<" "; cout<<endl; rep(i,0,fpodd.size())cout<<fpodd[i].val()<<" "; cout<<endl;*/ fps pw(4000000); rep(i,0,4000000){ pw[i]=pow_mod(i,k,mod); } mint ans=0; /*rep(i,0,fpeven.size()){ rep(j,0,fpodd.size()){ if(i%11!=j%11)continue; if((i+j)%9!=0)continue; //cout<<i<<" "<<j<<" "; ans+=pw[i+j]*fpeven[i]*fpodd[j]; //cout<<" : "<<ans.val()<<endl; j+=90; } }*/ rep(i,0,11){ fps fpeven2(fpeven.size(),0),fpodd2(fpodd.size(),0); rep(j,0,fpeven.size()){ if(j%11==i)fpeven2[j]=fpeven[j]; } rep(j,0,fpodd.size()){ if(j%11==i)fpodd2[j]=fpodd[j]; } fps fp3; fp3=convolution(fpeven2,fpodd2); rep(j,0,fp3.size()){ if(j%9==0){ ans+=pw[j]*fp3[j]; } } } cout<<ans.val()<<endl; } /* 9 の倍数 sum = 0 mod 9 11 の倍数 奇数桁 sum = 偶数桁 sum mod 11 */