結果

問題 No.2605 Pickup Parentheses
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-01-12 22:26:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,404 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 173,688 KB
実行使用メモリ 814,176 KB
最終ジャッジ日時 2024-01-12 22:27:21
合計ジャッジ時間 16,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,928 KB
testcase_01 AC 3 ms
9,928 KB
testcase_02 AC 3 ms
11,980 KB
testcase_03 AC 7 ms
12,000 KB
testcase_04 AC 6 ms
11,996 KB
testcase_05 AC 8 ms
12,136 KB
testcase_06 AC 11 ms
12,144 KB
testcase_07 AC 8 ms
12,008 KB
testcase_08 AC 12 ms
12,148 KB
testcase_09 AC 5 ms
12,000 KB
testcase_10 AC 9 ms
12,140 KB
testcase_11 AC 7 ms
11,996 KB
testcase_12 AC 5 ms
11,988 KB
testcase_13 AC 4 ms
12,032 KB
testcase_14 AC 6 ms
12,016 KB
testcase_15 AC 7 ms
12,028 KB
testcase_16 AC 4 ms
12,008 KB
testcase_17 AC 6 ms
12,016 KB
testcase_18 AC 430 ms
26,976 KB
testcase_19 AC 211 ms
19,768 KB
testcase_20 AC 43 ms
14,676 KB
testcase_21 AC 25 ms
14,304 KB
testcase_22 AC 11 ms
14,460 KB
testcase_23 AC 451 ms
27,812 KB
testcase_24 AC 40 ms
14,704 KB
testcase_25 AC 498 ms
29,908 KB
testcase_26 AC 530 ms
29,932 KB
testcase_27 AC 443 ms
27,788 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 57 ms
15,020 KB
testcase_30 AC 147 ms
20,032 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 309 ms
26,252 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 246 ms
23,320 KB
testcase_38 AC 110 ms
22,040 KB
testcase_39 AC 34 ms
14,996 KB
testcase_40 AC 254 ms
26,936 KB
testcase_41 AC 234 ms
30,516 KB
testcase_42 AC 332 ms
27,520 KB
testcase_43 AC 62 ms
17,856 KB
testcase_44 AC 63 ms
18,384 KB
testcase_45 AC 13 ms
12,360 KB
testcase_46 AC 25 ms
14,728 KB
testcase_47 AC 4 ms
9,928 KB
testcase_48 AC 51 ms
21,428 KB
testcase_49 AC 208 ms
23,436 KB
testcase_50 AC 95 ms
20,732 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 140 ms
21,992 KB
testcase_53 AC 200 ms
23,672 KB
testcase_54 AC 100 ms
20,148 KB
testcase_55 AC 148 ms
23,480 KB
testcase_56 AC 33 ms
14,948 KB
testcase_57 AC 2 ms
6,676 KB
testcase_58 AC 761 ms
29,676 KB
testcase_59 AC 457 ms
30,728 KB
testcase_60 AC 582 ms
30,648 KB
testcase_61 AC 542 ms
30,596 KB
testcase_62 AC 605 ms
29,720 KB
testcase_63 AC 598 ms
29,648 KB
testcase_64 AC 666 ms
30,456 KB
testcase_65 AC 476 ms
30,748 KB
testcase_66 AC 868 ms
29,100 KB
testcase_67 AC 561 ms
30,260 KB
testcase_68 MLE -
testcase_69 -- -
権限があれば一括ダウンロードができます

ソースコード

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>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
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<ll> work(ll l,ll r){
	if(l==r){
		vector<ll>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<ll>lf=work(l,mid);
	vector<ll>rg=work(mid+1,r);
	MUL(lf,rg,(ll)lf.size(),(ll)rg.size());
	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;
	rep(i,1,m){
		ll l=read(),r=read();
		a[i]=r-l+1;
	}
	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;
	vector<ll>f=work(1,m);
	ll ans=0;
	rep(i,0,min((ll)f.size()-1,n))ans=(ans+cat[(n-i)/2]*f[i])%Mod;
	write(ans);
	return 0;
}
0