結果

問題 No.2605 Pickup Parentheses
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-01-12 22:43:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 2,861 bytes
コンパイル時間 4,508 ms
コンパイル使用メモリ 246,500 KB
実行使用メモリ 26,780 KB
最終ジャッジ日時 2024-03-20 19:49:16
合計ジャッジ時間 11,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,932 KB
testcase_01 AC 3 ms
9,932 KB
testcase_02 AC 4 ms
9,932 KB
testcase_03 AC 5 ms
9,952 KB
testcase_04 AC 5 ms
9,948 KB
testcase_05 AC 5 ms
10,088 KB
testcase_06 AC 7 ms
10,096 KB
testcase_07 AC 6 ms
10,088 KB
testcase_08 AC 7 ms
12,148 KB
testcase_09 AC 4 ms
9,944 KB
testcase_10 AC 5 ms
10,092 KB
testcase_11 AC 4 ms
9,948 KB
testcase_12 AC 4 ms
9,940 KB
testcase_13 AC 4 ms
9,964 KB
testcase_14 AC 4 ms
9,968 KB
testcase_15 AC 6 ms
12,024 KB
testcase_16 AC 3 ms
9,940 KB
testcase_17 AC 5 ms
9,964 KB
testcase_18 AC 167 ms
22,600 KB
testcase_19 AC 85 ms
18,740 KB
testcase_20 AC 19 ms
12,628 KB
testcase_21 AC 13 ms
12,464 KB
testcase_22 AC 9 ms
12,268 KB
testcase_23 AC 165 ms
22,716 KB
testcase_24 AC 18 ms
12,652 KB
testcase_25 AC 211 ms
25,460 KB
testcase_26 AC 221 ms
25,872 KB
testcase_27 AC 142 ms
22,652 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 26 ms
12,844 KB
testcase_30 AC 64 ms
18,076 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 129 ms
23,764 KB
testcase_34 AC 1 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 106 ms
20,876 KB
testcase_38 AC 50 ms
18,296 KB
testcase_39 AC 20 ms
12,652 KB
testcase_40 AC 106 ms
21,960 KB
testcase_41 AC 107 ms
24,844 KB
testcase_42 AC 141 ms
22,692 KB
testcase_43 AC 32 ms
15,256 KB
testcase_44 AC 35 ms
17,568 KB
testcase_45 AC 13 ms
12,392 KB
testcase_46 AC 16 ms
12,536 KB
testcase_47 AC 4 ms
12,024 KB
testcase_48 AC 32 ms
18,860 KB
testcase_49 AC 99 ms
22,996 KB
testcase_50 AC 45 ms
17,480 KB
testcase_51 AC 1 ms
6,548 KB
testcase_52 AC 62 ms
18,184 KB
testcase_53 AC 84 ms
20,588 KB
testcase_54 AC 47 ms
17,612 KB
testcase_55 AC 74 ms
20,744 KB
testcase_56 AC 20 ms
12,728 KB
testcase_57 AC 3 ms
6,548 KB
testcase_58 AC 315 ms
26,284 KB
testcase_59 AC 178 ms
25,216 KB
testcase_60 AC 214 ms
25,260 KB
testcase_61 AC 204 ms
25,220 KB
testcase_62 AC 232 ms
25,560 KB
testcase_63 AC 214 ms
25,360 KB
testcase_64 AC 239 ms
26,116 KB
testcase_65 AC 189 ms
25,060 KB
testcase_66 AC 308 ms
26,780 KB
testcase_67 AC 206 ms
25,356 KB
testcase_68 AC 42 ms
18,732 KB
testcase_69 AC 2 ms
6,548 KB
testcase_70 AC 3 ms
9,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2605 Pickup Parentheses
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2605
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
#include<atcoder/all>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
using mint=atcoder::modint998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=2e6+9,Mod=998244353,G=3,IG=332748118;
ll n,m,a[N],fac[N],ifac[N],r[N],cat[N];
ll pw(ll x,ll p){
	ll res=1;
	while(p){
		if(p&1)res=res*x%Mod;
		x=x*x%Mod;
		p>>=1;
	}
	return res;
}
void NTT(vector<ll>&a,ll n,ll sgn){
	rep(i,0,n-1){
		if(i<r[i])swap(a[i],a[r[i]]);
	}
	for(ll mid=1;mid<n;mid*=2){
		ll Wn=pw(sgn==1?G:IG,(Mod-1)/(mid<<1));
		for(ll R=mid<<1,j=0;j<n;j+=R){
			ll w=1;
			for(ll k=0;k<mid;k++,w=w*Wn%Mod){
				ll x=a[j+k],y=a[j+k+mid]*w%Mod;
				a[j+k]=(x+y)%Mod,a[j+k+mid]=(x-y+Mod)%Mod;
			}
		}
	}
	if(sgn==-1){
        ll inv=pw(n,Mod-2);
        rep(i,0,n-1)a[i]=a[i]*inv%Mod;
    }
}
void MUL(vector<ll>&f,vector<ll>&g,ll n,ll m){
	ll mxlen=n+m;
	ll p=1,c=0;
	while(p<=mxlen)p<<=1,c++;
	f.resize(p),g.resize(p);
	r[0]=0;
	rep(i,1,p-1)r[i]=(r[i>>1]>>1)|((i&1)<<(c-1));
	NTT(f,p,1),NTT(g,p,1);
	rep(i,0,p-1)f[i]=f[i]*g[i]%Mod;
	NTT(f,p,-1);
	f.resize(n+m-1);
}
vector<mint> work(ll l,ll r){
	if(l==r){
		vector<mint>vec(a[l]+1,0);
		vec[0]=1;
		if(a[l]%2==0)vec[a[l]]=(Mod-cat[a[l]/2])%Mod;
		else {
			vec.clear();
			vec.push_back(1);
		}
		return vec;
	}
	ll mid=(l+r)>>1;
	vector<mint>lf=work(l,mid);
	vector<mint>rg=work(mid+1,r);
	lf=atcoder::convolution(lf,rg);
	return lf;
}
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),m=read();
	if(n&1)return puts("0"),0;
	queue<vector<mint> >q;
	
	fac[0]=1;
	rep(i,1,n*2)fac[i]=fac[i-1]*i%Mod;
	ifac[n*2]=pw(fac[n*2],Mod-2);
	per(i,n*2-1,0)ifac[i]=ifac[i+1]*(i+1)%Mod;
	cat[0]=1;
	rep(i,1,n)cat[i]=fac[i*2]*ifac[i]%Mod*ifac[i]%Mod*pw(i+1,Mod-2)%Mod;
	if(m==0){
	  cout<<cat[n/2];
	  return 0;
	}
	rep(i,1,m){
		ll l=read(),r=read();
		a[i]=r-l+1;
		if(a[i]%2==0){
	  	vector<mint>vec(a[i]+1,0);
		  vec[0]=1;
		  vec[a[i]]=(Mod-cat[a[i]/2])%Mod;
		q.push(vec);
		}
		else {
			vector<mint>vec(1,0);
			vec[0]=1;
		q.push(vec);
		}
	}
while(q.size()>1){
		auto f=q.front();q.pop();
		auto g=q.front();q.pop();
		q.push(atcoder::convolution(f,g));
	}
	auto f=q.front();
	mint ans=0;
	rep(i,0,min((ll)f.size()-1,n)){
	  if((n-i)%2==0)ans=(ans+mint(cat[(n-i)/2])*f[i]);
	}
	write(ans.val());
	return 0;
}
0