結果
問題 | No.1354 Sambo's Treasure |
ユーザー | kotatsugame |
提出日時 | 2021-01-17 14:06:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,535 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 84,348 KB |
実行使用メモリ | 51,028 KB |
最終ジャッジ日時 | 2024-05-07 02:54:37 |
合計ジャッジ時間 | 9,997 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
10,440 KB |
testcase_01 | AC | 7 ms
9,668 KB |
testcase_02 | AC | 7 ms
11,204 KB |
testcase_03 | AC | 6 ms
9,920 KB |
testcase_04 | AC | 7 ms
11,336 KB |
testcase_05 | AC | 7 ms
11,328 KB |
testcase_06 | AC | 7 ms
9,796 KB |
testcase_07 | AC | 6 ms
10,440 KB |
testcase_08 | AC | 7 ms
10,824 KB |
testcase_09 | AC | 6 ms
9,668 KB |
testcase_10 | AC | 6 ms
9,920 KB |
testcase_11 | AC | 7 ms
10,436 KB |
testcase_12 | AC | 6 ms
9,796 KB |
testcase_13 | AC | 7 ms
10,820 KB |
testcase_14 | AC | 7 ms
9,796 KB |
testcase_15 | AC | 7 ms
10,308 KB |
testcase_16 | AC | 7 ms
11,072 KB |
testcase_17 | AC | 7 ms
9,924 KB |
testcase_18 | AC | 6 ms
9,928 KB |
testcase_19 | AC | 6 ms
10,048 KB |
testcase_20 | AC | 7 ms
10,948 KB |
testcase_21 | AC | 6 ms
9,928 KB |
testcase_22 | AC | 6 ms
10,048 KB |
testcase_23 | AC | 91 ms
49,748 KB |
testcase_24 | AC | 91 ms
50,508 KB |
testcase_25 | AC | 112 ms
48,976 KB |
testcase_26 | AC | 114 ms
51,024 KB |
testcase_27 | AC | 102 ms
50,256 KB |
testcase_28 | AC | 93 ms
50,384 KB |
testcase_29 | AC | 116 ms
50,764 KB |
testcase_30 | AC | 101 ms
50,000 KB |
testcase_31 | AC | 103 ms
49,232 KB |
testcase_32 | AC | 102 ms
50,516 KB |
testcase_33 | AC | 91 ms
49,620 KB |
testcase_34 | AC | 103 ms
50,256 KB |
testcase_35 | AC | 92 ms
50,256 KB |
testcase_36 | AC | 103 ms
50,260 KB |
testcase_37 | AC | 94 ms
49,232 KB |
testcase_38 | AC | 112 ms
49,232 KB |
testcase_39 | AC | 115 ms
50,768 KB |
testcase_40 | AC | 120 ms
50,128 KB |
testcase_41 | AC | 90 ms
49,740 KB |
testcase_42 | AC | 114 ms
51,028 KB |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | RE | - |
testcase_59 | RE | - |
testcase_60 | RE | - |
testcase_61 | RE | - |
testcase_62 | RE | - |
testcase_63 | AC | 66 ms
10,052 KB |
コンパイルメッセージ
a.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#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[2<<17],inv[2<<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<2<<17;i++)fac[i]=fac[i-1]*i; inv[(2<<17)-1]=1/fac[(2<<17)-1]; for(int i=(2<<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; }