結果
問題 | No.2344 (l+r)^2 |
ユーザー | noya2 |
提出日時 | 2023-06-10 00:14:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,733 bytes |
コンパイル時間 | 5,682 ms |
コンパイル使用メモリ | 291,184 KB |
実行使用メモリ | 30,380 KB |
最終ジャッジ日時 | 2024-06-10 15:11:41 |
合計ジャッジ時間 | 6,884 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 63 ms
5,248 KB |
testcase_02 | AC | 14 ms
5,376 KB |
testcase_03 | AC | 15 ms
5,376 KB |
testcase_04 | AC | 15 ms
5,376 KB |
testcase_05 | AC | 15 ms
5,376 KB |
testcase_06 | AC | 15 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | AC | 143 ms
16,728 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
ソースコード
#line 1 "prayground.cpp" #include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for (int i = 0; i < int(n); ++i) #define repp(i,m,n) for (int i = m; i < int(n); ++i) #define reb(i,n) for (int i = int(n)-1; i >= 0; --i) #define all(v) v.begin(),v.end() using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using PL = pair<long long, long long>; using pdd = pair<long double, long double>; using pil = pair<int,ll>; using pli = pair<ll,int>; template<class T>istream &operator>>(istream &is,vector<T> &v){for(auto &e:v)is>>e;return is;} template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);} template<typename T>bool rrange(T a,T b,T c,T d,T x,T y){return (range(a,c,x)&&range(b,d,y));} template<typename T> T rev(const T& str_or_vec){T res = str_or_vec; reverse(res.begin(),res.end()); return res; } template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;} template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<typename T>void uniq(vector<T> &v){sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());} template<typename T1, typename T2>void print(pair<T1,T2> a); template<typename T>void print(vector<T> v); template<typename T>void print(vector<vector<T>> v); void print(){ putchar(' '); } void print(bool a){ printf("%d", a); } void print(int a){ printf("%d", a); } void print(long a){ printf("%ld", a); } void print(long long a){ printf("%lld", a); } void print(char a){ printf("%c", a); } void print(char a[]){ printf("%s", a); } void print(const char a[]){ printf("%s", a); } void print(long double a){ printf("%.15Lf", a); } void print(const string& a){ for(auto&& i : a) print(i); } void print(unsigned int a){ printf("%u", a); } void print(unsigned long long a) { printf("%llu", a); } template<class T> void print(const T& a){ cout << a; } int out(){ putchar('\n'); return 0; } template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; } template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; } template<typename T1,typename T2>void print(pair<T1,T2> a){print(a.first);print(),print(a.second);} template<typename T>void print(vector<T> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())print();}} template<typename T>void print(vector<vector<T>> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())out();}} void yes(){out("Yes");} void no (){out("No");} void yn (bool t){if(t)yes();else no();} void fast_io(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);} void o(){out("!?");} namespace noya2{ const int INF = 1001001007; const long long mod1 = 998244353; const long long mod2 = 1000000007; const long long inf = 2e18; const long double pi = 3.14159265358979323; const long double eps = 1e-7; const vector<int> dx = {0,1,0,-1,1,1,-1,-1}; const vector<int> dy = {1,0,-1,0,1,-1,-1,1}; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string alp = "abcdefghijklmnopqrstuvwxyz"; const string NUM = "0123456789"; } // namespace noya2 using namespace noya2; using mint = modint998244353; //using mint = modint1000000007; //using mint = modint; void out(mint a){out(a.val());} void out(vector<mint> a){vector<ll> b(a.size()); rep(i,a.size()) b[i] = a[i].val(); out(b);} void out(vector<vector<mint>> a){for (auto v : a) out(v);} #line 2 "convolution.hpp" #line 2 "NTT.hpp" #line 4 "NTT.hpp" template<long long m> struct NTT{ using mint = static_modint<m>; NTT(){init();}; static void FFT(vector<mint> &a){ int n = a.size(); int siz = 1; while (siz < n) siz <<= 1; a.resize(siz); fft(a,1); } static void IFFT(vector<mint> &a){ int n = a.size(); int siz = 1; while (siz < n) siz <<= 1; mint div = mint(siz).inv(); a.resize(siz); fft(a,-1); for (auto &x : a) x *= div; } static void DFT(vector<mint> &a, int inv){fft(a,inv);} static vector<long long> multiply(vector<long long> a, vector<long long> b){ vector<mint> na(a.size()), nb(b.size()); for (int i = 0; i < (int)a.size(); i++) na[i] = a[i]; for (int i = 0; i < (int)b.size(); i++) nb[i] = b[i]; vector<mint> nc = multiply(na,nb); vector<long long> c(nc.size()); for (int i = 0; i < (int)nc.size(); i++) c[i] = nc[i].val(); return c; } static vector<mint> multiply(vector<mint> a, vector<mint> b){ int n = a.size() + b.size() - 1; int siz = 1; while (siz < n) siz <<= 1; a.resize(siz), b.resize(siz); FFT(a), FFT(b); for (int i = 0; i < siz; i++) a[i] *= b[i]; IFFT(a); a.resize(n); return a; } private: static static_modint<m> g; static int limit; static vector<static_modint<m>>root, inv_root; static constexpr mint primitive_root(const long long &mo){ if (mo == 2) return mint(1); if (mo == 167772161) return mint(3); if (mo == 469762049) return mint(3); if (mo == 754974721) return mint(11); if (mo == 998244353) return mint(3); if (mo == 1224736769)return mint(3); return mint(); // atode kaku } static void init(){ if (!root.empty()) return ; g = primitive_root(m); long long now = m-1; while ((now & 1) == 0) now >>= 1, limit++; root.resize(limit+1,1), inv_root.resize(limit+1,1); root[limit] = g.pow(now), inv_root[limit] /= root[limit]; for(int i = limit-1; i >= 0; i--){ root[i] = root[i+1] * root[i+1]; inv_root[i] = inv_root[i+1] * inv_root[i+1]; } } static int bits_msb(int v){ v = v | (v >> 1); v = v | (v >> 2); v = v | (v >> 4); v = v | (v >> 8); v = v | (v >> 16); return v ^ (v >> 1); } static int pre(int v, int n){ return v ^ (n - bits_msb(v)); } static void fft(vector<mint> &a, int inv){ init(); int n = a.size(); if (n == 1) return ; int d = 0; while ((n >> d & 1) == 0) d++; vector<int> idx(n); idx[n-1] = n-1; for (int i = n-2; i >= 0; i--) idx[i] = pre(idx[i+1],n); vector<mint> na = a; for (int i = 0; i < n; i++) a[i] = na[idx[i]]; for (int i = 0; i < d; i++){ int width = 1 << (i+1); vector<mint> gp(width/2,1); if (inv == 1) for (int j = 0; j < width/2-1; j++) gp[j+1] = gp[j] * root[i+1]; if (inv == -1) for (int j = 0; j < width/2-1; j++) gp[j+1] = gp[j] * inv_root[i+1]; for (int j = 0; j < n; j += width){ for (int k = 0; k < width/2; k++){ mint lhs = a[j+k], rhs = a[j+k+width/2] * gp[k]; a[j+k] = lhs + rhs; a[j+k+width/2] = lhs - rhs; } } } } }; template<long long m> int NTT<m>::limit=0; template<long long m> vector<static_modint<m>>NTT<m>::root=vector<static_modint<m>>(); template<long long m> vector<static_modint<m>>NTT<m>::inv_root=vector<static_modint<m>>(); template<long long m> static_modint<m>NTT<m>::g=static_modint<m>(); #line 5 "convolution.hpp" namespace noya2{ using ll = long long; using namespace std; template<typename T> vector<T> convolution(vector<T> a, vector<T> b){ // T = ll, modint998244353 return NTT<998244353>::multiply(a,b); } template<ll MOD> vector<ll> arbitrary_mod_convolution(vector<ll> a, vector<ll> b){ static constexpr ll m1 = 167772161, m2 = 469762049, m3 = 1224736769; static constexpr ll m1_inv_m2 = 104391568, m12_inv_m3 = 721017874; const ll m12_mod = 78812994116517889LL % MOD; auto c1 = NTT<m1>::multiply(a,b); auto c2 = NTT<m2>::multiply(a,b); auto c3 = NTT<m3>::multiply(a,b); vector<ll> res(c1.size()); for (int i = 0; i < (int)res.size(); i++){ ll t1 = c1[i]; ll t2 = (c2[i] - c1[i]) * m1_inv_m2 % m2; if (t2 < 0) t2 += m2; ll t3 = (c3[i] - (t1 + t2 * m1) % m3) * m12_inv_m3 % m3; if (t3 < 0) t3 += m3; res[i] = (t1 + t2 * m1 + t3 * m12_mod) % MOD; if (res[i] < 0) res[i] += MOD; } return res; } } // namespace noya2 #line 78 "prayground.cpp" void solve(){ int n, m; cin >> n >> m; vector<ll> a(n); cin >> a; const ll md = 1<<m; if (n <= 100){ rep(i,n-1){ vector<ll> b(n-1-i); rep(j,n-1-i) b[j] = (a[j]+a[j+1])*(a[j]+a[j+1]) % md; swap(a,b); } out(a[0]); return ; } int nn = n-100; vector<ll> b(nn+1,1); auto get = [&](int x){ int t = 0; while ((x & 1) == 0){ t++; x >>= 1; } return P(x,t); }; ll cur = 1; int ni = 0; for (int i = 1; i <= nn; i++){ auto [pv, pt] = get(nn+1-i); cur = cur * pv % md; ni += pt; auto [qv, qt] = get(i); cur = cur * inv_mod(qv,md) % md; ni -= qt; if (ni >= m) b[i] = 0; else b[i] = (cur << ni) % md; } rep(i,nn+1) if (i % 2 == 1) b[i] = (md-b[i])%md; auto c = arbitrary_mod_convolution<1LL<<30>(a,b); for (auto &x : c) x %= md; int siz = c.size(); vector<ll> d(100); reb(i,100) d[i] = c[siz-1-i]; rep(i,99){ vector<ll> e(99-i); rep(j,99-i) e[j] = (d[j]+d[j+1])*(d[j]+d[j+1]) % md; swap(e,d); } out(d[0]); } int main(){ fast_io(); int t = 1; cin >> t; while(t--) solve(); }