結果
問題 | No.2605 Pickup Parentheses |
ユーザー | Jeroen Op de Beek |
提出日時 | 2024-01-12 21:53:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 5,025 bytes |
コンパイル時間 | 2,615 ms |
コンパイル使用メモリ | 209,760 KB |
実行使用メモリ | 813,260 KB |
最終ジャッジ日時 | 2024-09-27 22:00:27 |
合計ジャッジ時間 | 15,535 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
23,116 KB |
testcase_01 | AC | 34 ms
23,120 KB |
testcase_02 | AC | 35 ms
23,116 KB |
testcase_03 | AC | 35 ms
23,120 KB |
testcase_04 | AC | 37 ms
23,116 KB |
testcase_05 | AC | 37 ms
23,116 KB |
testcase_06 | AC | 38 ms
23,240 KB |
testcase_07 | AC | 37 ms
23,116 KB |
testcase_08 | AC | 39 ms
22,988 KB |
testcase_09 | AC | 36 ms
23,120 KB |
testcase_10 | AC | 36 ms
22,988 KB |
testcase_11 | AC | 36 ms
22,992 KB |
testcase_12 | AC | 36 ms
23,240 KB |
testcase_13 | AC | 35 ms
23,116 KB |
testcase_14 | AC | 35 ms
23,112 KB |
testcase_15 | AC | 36 ms
23,244 KB |
testcase_16 | AC | 35 ms
23,244 KB |
testcase_17 | AC | 36 ms
23,248 KB |
testcase_18 | AC | 263 ms
24,392 KB |
testcase_19 | AC | 138 ms
23,756 KB |
testcase_20 | AC | 53 ms
23,368 KB |
testcase_21 | AC | 45 ms
23,116 KB |
testcase_22 | AC | 38 ms
22,988 KB |
testcase_23 | AC | 262 ms
24,388 KB |
testcase_24 | AC | 52 ms
23,368 KB |
testcase_25 | AC | 279 ms
24,756 KB |
testcase_26 | AC | 296 ms
24,900 KB |
testcase_27 | AC | 243 ms
24,708 KB |
testcase_28 | AC | 145 ms
24,012 KB |
testcase_29 | AC | 56 ms
23,244 KB |
testcase_30 | AC | 92 ms
23,372 KB |
testcase_31 | AC | 86 ms
23,372 KB |
testcase_32 | AC | 56 ms
23,376 KB |
testcase_33 | AC | 158 ms
23,884 KB |
testcase_34 | AC | 149 ms
24,008 KB |
testcase_35 | AC | 130 ms
23,704 KB |
testcase_36 | AC | 136 ms
23,628 KB |
testcase_37 | AC | 143 ms
23,752 KB |
testcase_38 | AC | 87 ms
23,496 KB |
testcase_39 | AC | 50 ms
23,244 KB |
testcase_40 | AC | 179 ms
24,316 KB |
testcase_41 | AC | 159 ms
24,436 KB |
testcase_42 | AC | 209 ms
24,688 KB |
testcase_43 | AC | 66 ms
23,372 KB |
testcase_44 | AC | 64 ms
23,628 KB |
testcase_45 | AC | 36 ms
23,120 KB |
testcase_46 | AC | 46 ms
23,116 KB |
testcase_47 | AC | 34 ms
23,116 KB |
testcase_48 | AC | 36 ms
23,244 KB |
testcase_49 | AC | 127 ms
23,852 KB |
testcase_50 | AC | 68 ms
23,372 KB |
testcase_51 | AC | 86 ms
23,628 KB |
testcase_52 | AC | 94 ms
23,632 KB |
testcase_53 | AC | 122 ms
23,760 KB |
testcase_54 | AC | 75 ms
23,428 KB |
testcase_55 | AC | 100 ms
23,664 KB |
testcase_56 | AC | 49 ms
23,372 KB |
testcase_57 | AC | 89 ms
23,756 KB |
testcase_58 | AC | 371 ms
25,212 KB |
testcase_59 | AC | 278 ms
24,376 KB |
testcase_60 | AC | 330 ms
24,876 KB |
testcase_61 | AC | 306 ms
24,732 KB |
testcase_62 | AC | 316 ms
24,616 KB |
testcase_63 | AC | 319 ms
24,620 KB |
testcase_64 | AC | 356 ms
24,560 KB |
testcase_65 | AC | 270 ms
24,712 KB |
testcase_66 | AC | 432 ms
24,992 KB |
testcase_67 | AC | 301 ms
24,612 KB |
testcase_68 | MLE | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
ソースコード
#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> { // 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'; }