結果

問題 No.1354 Sambo's Treasure
ユーザー kotatsugamekotatsugame
提出日時 2021-01-17 14:07:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 4,535 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 82,736 KB
実行使用メモリ 53,280 KB
最終ジャッジ日時 2023-08-22 08:09:21
合計ジャッジ時間 5,986 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
12,124 KB
testcase_01 AC 9 ms
12,368 KB
testcase_02 AC 9 ms
12,128 KB
testcase_03 AC 9 ms
12,072 KB
testcase_04 AC 8 ms
12,148 KB
testcase_05 AC 9 ms
12,120 KB
testcase_06 AC 9 ms
12,112 KB
testcase_07 AC 9 ms
12,092 KB
testcase_08 AC 9 ms
12,088 KB
testcase_09 AC 9 ms
12,108 KB
testcase_10 AC 9 ms
12,260 KB
testcase_11 AC 9 ms
12,100 KB
testcase_12 AC 9 ms
12,192 KB
testcase_13 AC 9 ms
12,108 KB
testcase_14 AC 8 ms
12,196 KB
testcase_15 AC 9 ms
12,080 KB
testcase_16 AC 9 ms
12,116 KB
testcase_17 AC 8 ms
12,176 KB
testcase_18 AC 8 ms
12,084 KB
testcase_19 AC 9 ms
12,084 KB
testcase_20 AC 9 ms
12,136 KB
testcase_21 AC 9 ms
12,180 KB
testcase_22 AC 9 ms
12,124 KB
testcase_23 AC 88 ms
53,280 KB
testcase_24 AC 87 ms
53,012 KB
testcase_25 AC 109 ms
52,996 KB
testcase_26 AC 109 ms
53,072 KB
testcase_27 AC 98 ms
53,040 KB
testcase_28 AC 88 ms
53,012 KB
testcase_29 AC 113 ms
52,984 KB
testcase_30 AC 98 ms
53,140 KB
testcase_31 AC 99 ms
53,000 KB
testcase_32 AC 97 ms
53,072 KB
testcase_33 AC 87 ms
53,264 KB
testcase_34 AC 98 ms
53,144 KB
testcase_35 AC 88 ms
53,008 KB
testcase_36 AC 100 ms
53,072 KB
testcase_37 AC 87 ms
53,024 KB
testcase_38 AC 110 ms
53,028 KB
testcase_39 AC 111 ms
53,016 KB
testcase_40 AC 112 ms
53,008 KB
testcase_41 AC 87 ms
53,016 KB
testcase_42 AC 110 ms
52,980 KB
testcase_43 AC 10 ms
12,148 KB
testcase_44 AC 10 ms
12,400 KB
testcase_45 AC 11 ms
12,412 KB
testcase_46 AC 10 ms
12,216 KB
testcase_47 AC 11 ms
12,164 KB
testcase_48 AC 11 ms
12,116 KB
testcase_49 AC 10 ms
12,236 KB
testcase_50 AC 10 ms
12,276 KB
testcase_51 AC 11 ms
12,128 KB
testcase_52 AC 10 ms
12,416 KB
testcase_53 AC 10 ms
12,196 KB
testcase_54 AC 10 ms
12,144 KB
testcase_55 AC 10 ms
12,272 KB
testcase_56 AC 12 ms
12,172 KB
testcase_57 AC 12 ms
12,216 KB
testcase_58 AC 10 ms
12,212 KB
testcase_59 AC 10 ms
12,400 KB
testcase_60 AC 10 ms
12,136 KB
testcase_61 AC 11 ms
12,176 KB
testcase_62 AC 11 ms
12,224 KB
testcase_63 AC 63 ms
12,080 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:15:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#line 3 "/home/kotatsugame/library/math/modint.cpp"
#include<utility>
template<int m>
struct modint{
	unsigned int x;
	constexpr modint()noexcept:x(){}
	template<typename T>
	constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){}
	constexpr unsigned int val()const noexcept{return x;}
	constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;}
	constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;}
	constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;}
	constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;}
	constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;}
	constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;}
	constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;}
	constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();}
	constexpr modint operator+()const noexcept{return*this;}
	constexpr modint operator-()const noexcept{return modint()-*this;}
	constexpr modint pow(long long n)const noexcept
	{
		if(n<0)return pow(-n).inv();
		modint x=*this,r=1;
		for(;n;x*=x,n>>=1)if(n&1)r*=x;
		return r;
	}
	constexpr modint inv()const noexcept
	{
		int s=x,t=m,x=1,u=0;
		while(t)
		{
			int k=s/t;
			s-=k*t;
			swap(s,t);
			x-=k*u;
			swap(x,u);
		}
		return modint(x);
	}
	friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
	friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
	friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
	friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
	friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;}
	friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;}
	friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;}
	friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;}
};
#line 6 "a.cpp"
using mint=modint<998244353>;
mint fac[4<<17],inv[4<<17];
mint comb(int a,int b){return fac[a]*inv[b]*inv[a-b];}
int N,M,L,K;
int Xc[1<<17],Yc[1<<17];
vector<pair<int,int> >G[1<<17];
mint dp[1<<17][101];
mint ep[111][101];
mint F[111];
main()
{
	fac[0]=1;
	for(int i=1;i<4<<17;i++)fac[i]=fac[i-1]*i;
	inv[(4<<17)-1]=1/fac[(4<<17)-1];
	for(int i=(4<<17)-1;i--;)inv[i]=inv[i+1]*(i+1);
	cin>>N>>M>>L>>K;
	for(int i=1;i<=M;i++)cin>>Xc[i]>>Yc[i];
	Xc[M+1]=Yc[M+1]=N;
	if(K>=L)
	{
		mint ans=1;
		for(int i=1;i<=M+1;i++)
		{
			int dx=Xc[i]-Xc[i-1];
			int dy=Yc[i]-Yc[i-1];
			ans*=comb(dx+dy,dx);
		}
		cout<<ans<<endl;
		return 0;
	}
	for(int i=0;i<L;i++)
	{
		int x,y;cin>>x>>y;
		for(int i=0;i<M+1;i++)
		{
			if(Xc[i]<=x&&x<=Xc[i+1]&&Yc[i]<=y&&y<=Yc[i+1])
			{
				G[i].push_back(make_pair(x,y));
				break;
			}
			else if(x<Xc[i])break;
		}
		/*
		int id=upper_bound(Xc,Xc+M+2,x)-Xc-1;
		if(Xc[id]<x)
		{
			if(Yc[id]>y||Yc[id+1]<y)continue;
			G[id].push_back(make_pair(x,y));
		}
		else
		{
			if(Yc[id]>y)
			{
				if(Yc[id-1]<=y)
				{
					G[id-1].push_back(make_pair(x,y));
				}
			}
			else if(Yc[id+1]<y)continue;
			else
			{
				G[id].push_back(make_pair(x,y));
			}
		}*/
	}
	dp[0][K]=1;
	for(int i=0;i<M+1;i++)
	{
		sort(G[i].begin(),G[i].end());
		vector<pair<int,int> >pt=G[i];
		pt.push_back(make_pair(Xc[i],Yc[i]));
		pt.push_back(make_pair(Xc[i+1],Yc[i+1]));
		sort(pt.begin(),pt.end());
		pt.erase(unique(pt.begin(),pt.end()),pt.end());
		for(int j=0;j<pt.size();j++)for(int k=0;k<=K;k++)ep[j][k]=0;
		for(int k=0;k<=K;k++)ep[0][k]=dp[i][k];
		for(int j=0;j<pt.size();j++)
		{
			{
				auto it=lower_bound(G[i].begin(),G[i].end(),pt[j]);
				if(it!=G[i].end()&&*it==pt[j])
				{
					for(int k=0;k<K;k++)ep[j][k]=ep[j][k+1];
					ep[j][K]=0;
				}
			}
			for(int l=j+1;l<pt.size();l++)F[l]=0;
			for(int l=j+1;l<pt.size();l++)
			{
				int lx=pt[j].first,ly=pt[j].second;
				int rx=pt[l].first,ry=pt[l].second;
				if(lx>rx||ly>ry)continue;
				mint now=comb(rx-lx+ry-ly,rx-lx);
				for(int m=j+1;m<l;m++)
				{
					int x=pt[m].first,y=pt[m].second;
					if(!(lx<=x&&x<=rx&&ly<=y&&y<=ry))continue;
					now-=F[m]*comb(rx-x+ry-y,rx-x);
				}
				F[l]=now;
				for(int k=0;k<=K;k++)ep[l][k]+=ep[j][k]*F[l];
			}
		}
		for(int k=0;k<=K;k++)dp[i+1][k]=ep[pt.size()-1][k];
	}
	mint ans=0;
	for(int k=0;k<=K;k++)ans+=dp[M+1][k];
	cout<<ans<<endl;
}
0