結果
問題 | No.2605 Pickup Parentheses |
ユーザー | Jeroen Op de Beek |
提出日時 | 2024-01-12 21:48:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,889 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 207,732 KB |
実行使用メモリ | 816,768 KB |
最終ジャッジ日時 | 2024-09-27 21:54:32 |
合計ジャッジ時間 | 23,680 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
23,244 KB |
testcase_01 | AC | 34 ms
23,168 KB |
testcase_02 | AC | 35 ms
23,040 KB |
testcase_03 | AC | 37 ms
23,244 KB |
testcase_04 | AC | 38 ms
23,168 KB |
testcase_05 | AC | 39 ms
23,296 KB |
testcase_06 | AC | 41 ms
23,244 KB |
testcase_07 | AC | 39 ms
23,368 KB |
testcase_08 | AC | 43 ms
23,240 KB |
testcase_09 | AC | 37 ms
23,168 KB |
testcase_10 | AC | 39 ms
23,296 KB |
testcase_11 | AC | 37 ms
23,168 KB |
testcase_12 | AC | 35 ms
23,168 KB |
testcase_13 | AC | 37 ms
23,116 KB |
testcase_14 | AC | 40 ms
23,296 KB |
testcase_15 | AC | 41 ms
23,296 KB |
testcase_16 | AC | 35 ms
23,244 KB |
testcase_17 | AC | 38 ms
23,248 KB |
testcase_18 | AC | 448 ms
25,904 KB |
testcase_19 | AC | 240 ms
24,524 KB |
testcase_20 | AC | 72 ms
23,552 KB |
testcase_21 | AC | 55 ms
23,248 KB |
testcase_22 | AC | 44 ms
23,424 KB |
testcase_23 | AC | 450 ms
25,868 KB |
testcase_24 | AC | 73 ms
23,524 KB |
testcase_25 | AC | 507 ms
26,132 KB |
testcase_26 | AC | 517 ms
26,064 KB |
testcase_27 | AC | 427 ms
25,952 KB |
testcase_28 | AC | 542 ms
26,680 KB |
testcase_29 | AC | 139 ms
24,064 KB |
testcase_30 | AC | 274 ms
24,520 KB |
testcase_31 | AC | 254 ms
24,896 KB |
testcase_32 | AC | 129 ms
23,632 KB |
testcase_33 | AC | 521 ms
26,688 KB |
testcase_34 | AC | 517 ms
26,624 KB |
testcase_35 | AC | 378 ms
26,704 KB |
testcase_36 | AC | 478 ms
26,560 KB |
testcase_37 | AC | 479 ms
26,160 KB |
testcase_38 | AC | 129 ms
24,592 KB |
testcase_39 | AC | 63 ms
23,252 KB |
testcase_40 | AC | 270 ms
25,448 KB |
testcase_41 | AC | 237 ms
26,196 KB |
testcase_42 | AC | 336 ms
26,684 KB |
testcase_43 | AC | 92 ms
23,756 KB |
testcase_44 | AC | 87 ms
23,892 KB |
testcase_45 | AC | 35 ms
23,168 KB |
testcase_46 | AC | 55 ms
23,496 KB |
testcase_47 | AC | 34 ms
23,168 KB |
testcase_48 | AC | 180 ms
26,324 KB |
testcase_49 | AC | 375 ms
26,532 KB |
testcase_50 | AC | 181 ms
24,616 KB |
testcase_51 | AC | 315 ms
26,364 KB |
testcase_52 | AC | 208 ms
24,660 KB |
testcase_53 | AC | 300 ms
26,004 KB |
testcase_54 | AC | 177 ms
24,724 KB |
testcase_55 | AC | 280 ms
26,464 KB |
testcase_56 | AC | 88 ms
23,884 KB |
testcase_57 | AC | 339 ms
26,648 KB |
testcase_58 | AC | 637 ms
26,852 KB |
testcase_59 | AC | 465 ms
26,324 KB |
testcase_60 | AC | 558 ms
26,412 KB |
testcase_61 | AC | 553 ms
26,620 KB |
testcase_62 | AC | 590 ms
26,108 KB |
testcase_63 | AC | 553 ms
26,496 KB |
testcase_64 | AC | 626 ms
26,576 KB |
testcase_65 | AC | 471 ms
26,580 KB |
testcase_66 | AC | 744 ms
26,344 KB |
testcase_67 | AC | 534 ms
26,632 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() { precomp(); precomp2(); int n,m; cin >> n >> m; vi ws(m); for(int i=0;i<m;++i) { int l,r; cin >> l >> r; --l,--r; ws[i] = r-l+1; } auto mul = [&](auto&& self, int l, int r) -> vector<mint> { // cerr << l << ' ' << r << '\n'; if(l+1==r) { vector<mint> v(ws[l]+1); v[ws[l]]=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)); }; auto res = mul(mul,0,m); // normally: n brackets mint ans=0; for(int i=0;i<res.size();++i) { ans+=catalan(n-i)*res[i]; } cout << ans << '\n'; }