結果
問題 | No.2605 Pickup Parentheses |
ユーザー | Jeroen Op de Beek |
提出日時 | 2024-01-12 21:54:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 384 ms / 2,000 ms |
コード長 | 5,054 bytes |
コンパイル時間 | 2,137 ms |
コンパイル使用メモリ | 210,532 KB |
実行使用メモリ | 25,088 KB |
最終ジャッジ日時 | 2024-09-30 06:21:48 |
合計ジャッジ時間 | 11,483 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
23,244 KB |
testcase_01 | AC | 29 ms
23,112 KB |
testcase_02 | AC | 29 ms
23,120 KB |
testcase_03 | AC | 31 ms
23,112 KB |
testcase_04 | AC | 30 ms
23,244 KB |
testcase_05 | AC | 31 ms
23,120 KB |
testcase_06 | AC | 31 ms
23,120 KB |
testcase_07 | AC | 30 ms
23,244 KB |
testcase_08 | AC | 31 ms
23,240 KB |
testcase_09 | AC | 29 ms
23,240 KB |
testcase_10 | AC | 31 ms
23,112 KB |
testcase_11 | AC | 30 ms
23,244 KB |
testcase_12 | AC | 32 ms
23,116 KB |
testcase_13 | AC | 31 ms
23,244 KB |
testcase_14 | AC | 32 ms
23,112 KB |
testcase_15 | AC | 31 ms
23,116 KB |
testcase_16 | AC | 30 ms
23,120 KB |
testcase_17 | AC | 31 ms
23,116 KB |
testcase_18 | AC | 222 ms
24,512 KB |
testcase_19 | AC | 125 ms
24,008 KB |
testcase_20 | AC | 46 ms
23,372 KB |
testcase_21 | AC | 39 ms
23,244 KB |
testcase_22 | AC | 33 ms
23,116 KB |
testcase_23 | AC | 234 ms
24,644 KB |
testcase_24 | AC | 48 ms
23,372 KB |
testcase_25 | AC | 241 ms
24,756 KB |
testcase_26 | AC | 266 ms
24,900 KB |
testcase_27 | AC | 227 ms
24,708 KB |
testcase_28 | AC | 135 ms
24,008 KB |
testcase_29 | AC | 51 ms
23,244 KB |
testcase_30 | AC | 85 ms
23,360 KB |
testcase_31 | AC | 74 ms
23,372 KB |
testcase_32 | AC | 49 ms
23,372 KB |
testcase_33 | AC | 144 ms
24,140 KB |
testcase_34 | AC | 140 ms
24,012 KB |
testcase_35 | AC | 104 ms
23,836 KB |
testcase_36 | AC | 122 ms
23,856 KB |
testcase_37 | AC | 135 ms
23,884 KB |
testcase_38 | AC | 78 ms
23,500 KB |
testcase_39 | AC | 45 ms
23,372 KB |
testcase_40 | AC | 151 ms
24,180 KB |
testcase_41 | AC | 135 ms
24,560 KB |
testcase_42 | AC | 180 ms
24,692 KB |
testcase_43 | AC | 57 ms
23,500 KB |
testcase_44 | AC | 56 ms
23,500 KB |
testcase_45 | AC | 29 ms
23,116 KB |
testcase_46 | AC | 37 ms
23,372 KB |
testcase_47 | AC | 29 ms
23,244 KB |
testcase_48 | AC | 30 ms
23,244 KB |
testcase_49 | AC | 115 ms
23,984 KB |
testcase_50 | AC | 59 ms
23,500 KB |
testcase_51 | AC | 79 ms
23,632 KB |
testcase_52 | AC | 85 ms
23,628 KB |
testcase_53 | AC | 117 ms
23,884 KB |
testcase_54 | AC | 66 ms
23,500 KB |
testcase_55 | AC | 88 ms
23,668 KB |
testcase_56 | AC | 42 ms
23,248 KB |
testcase_57 | AC | 78 ms
23,628 KB |
testcase_58 | AC | 329 ms
25,088 KB |
testcase_59 | AC | 243 ms
24,244 KB |
testcase_60 | AC | 295 ms
24,876 KB |
testcase_61 | AC | 280 ms
24,604 KB |
testcase_62 | AC | 278 ms
24,616 KB |
testcase_63 | AC | 287 ms
24,748 KB |
testcase_64 | AC | 324 ms
24,832 KB |
testcase_65 | AC | 244 ms
24,588 KB |
testcase_66 | AC | 384 ms
25,004 KB |
testcase_67 | AC | 290 ms
24,612 KB |
testcase_68 | AC | 32 ms
23,240 KB |
testcase_69 | AC | 32 ms
23,244 KB |
testcase_70 | AC | 30 ms
23,248 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1<<20, oo = 1e9; const long long MD = 998244353; template<long long MOD=MD> struct mdint { int d; mdint () {d=0;} mdint (long long _d) : d(_d%MOD){ if(d<0) d+=MOD; }; friend mdint& operator+=(mdint& a, const mdint& o) { a.d+=o.d; if(a.d>=MOD) a.d-=MOD; return a; } friend mdint& operator-=(mdint& a, const mdint& o) { a.d-=o.d; if(a.d<0) a.d+=MOD; return a; } friend mdint& operator*=(mdint& a, const mdint& o) { return a = mdint((ll)a.d*o.d); } mdint operator*(const mdint& o) const { mdint res = *this; res*=o; return res; } mdint operator+(const mdint& o) const { mdint res = *this; res+=o; return res; } mdint operator-(const mdint& o) const { mdint res = *this; res-=o; return res; } mdint operator^(long long b) const { mdint tmp = 1; mdint power = *this; while(b) { if(b&1) { tmp = tmp*power; } power = power*power; b/=2; } return tmp; } friend mdint operator/=(mdint& a, const mdint& o) { a *= (o^(MOD-2)); return a; } mdint operator/(const mdint& o) { mdint res = *this; res/=o; return res; } bool operator==(const mdint& o) { return d==o.d;} bool operator!=(const mdint& o) { return d!=o.d;} friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;} friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;} }; using mint = mdint<MD>; const int mxF = 2e6+2; mint fact[mxF], ifact[mxF]; mint ncr(int a, int b) { if(b>a or a<0 or b<0) return 0; return fact[a]*ifact[b]*ifact[a-b]; } void precomp() { fact[0]=1; for(int i=1;i<mxF;++i) { fact[i]=fact[i-1]*i; } ifact[mxF-1] = mint(1)/fact[mxF-1]; for(int i=mxF-2;i>=0;--i) { ifact[i]=ifact[i+1]*(i+1); } } typedef mint cd; void revperm(cd* in, int n) { for(int i=0,j=0;i<n;++i) { if(i<j) swap(in[i],in[j]); for(int k = n >> 1; (j ^= k) < k; k >>= 1); } } cd w[mxN+1]; // stores w^j for each j in [0,n-1] void precomp2() { w[0] = 1; int pw = (MD-1)/mxN; w[1] = mint(3)^pw; for(int i= 2;i<=mxN;++i) { w[i] = w[i-1]*w[1]; } } void fft(cd* in, int n, bool reverse=false) { int lg = __lg(n); assert(1<<lg == n); int stride = mxN/n; revperm(in,n); for(int s=1;s<=lg;++s) { int pw = 1<<s; int mstride = stride*(n>>s); for(int j=0;j<n;j+=pw) { // do FFT merging on out array cd* even = in+j, *odd = in+j+pw/2; for(int i=0;i<pw/2;++i) { cd& power = w[reverse?mxN-mstride*i:mstride*i]; auto tmp = power*odd[i]; odd[i] = even[i] - tmp; even[i] = even[i] + tmp; } } } if(reverse) { mint fac = mint(1)/n; for(int i=0;i<n;++i) in[i]=in[i]*fac; } } vector<cd> polymul(vector<cd> a, vector<cd> b) { int n = a.size(), m = b.size(), ptwo = 1; while(ptwo<(n+m)) ptwo*=2; a.resize(ptwo), b.resize(ptwo); fft(a.data(),ptwo); fft(b.data(),ptwo); for(int i=0;i<ptwo;++i) a[i] = a[i]*b[i]; fft(a.data(),ptwo,true); a.resize(n+m-1); return a; } mint catalan(int n) { if(n%2==1) return 0; n/=2; return ncr(2*n,n)/(n+1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); precomp(); precomp2(); int n,m; cin >> n >> m; vi ws; for(int i=0;i<m;++i) { int l,r; cin >> l >> r; --l,--r; if((r-l+1)%2==0) { ws.push_back(r-l+1); } } m = ws.size(); auto mul = [&](auto&& self, int l, int r) -> vector<mint> { if(l==r) return {1}; // cerr << l << ' ' << r << '\n'; if(l+1==r) { vector<mint> v( (ws[l]/2+1)); v[ws[l]/2]=mint(0)-catalan(ws[l]); v[0]+=1; return v; } auto mid = (l+r)/2; return polymul(self(self,l,mid), self(self,mid,r)); }; vector<mint> res = mul(mul,0,m); // normally: n brackets mint ans=0; for(int i=0;i<res.size();++i) { ans+=catalan(n-i*2)*res[i]; } cout << ans << '\n'; }