結果
問題 | No.1354 Sambo's Treasure |
ユーザー | kotatsugame |
提出日時 | 2021-01-17 14:07:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 127 ms / 2,000 ms |
コード長 | 4,535 bytes |
コンパイル時間 | 1,231 ms |
コンパイル使用メモリ | 83,216 KB |
実行使用メモリ | 53,072 KB |
最終ジャッジ日時 | 2024-12-16 03:49:26 |
合計ジャッジ時間 | 5,970 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
12,544 KB |
testcase_01 | AC | 10 ms
12,824 KB |
testcase_02 | AC | 10 ms
12,288 KB |
testcase_03 | AC | 11 ms
13,504 KB |
testcase_04 | AC | 10 ms
12,868 KB |
testcase_05 | AC | 10 ms
12,216 KB |
testcase_06 | AC | 10 ms
12,692 KB |
testcase_07 | AC | 9 ms
12,592 KB |
testcase_08 | AC | 10 ms
12,412 KB |
testcase_09 | AC | 10 ms
11,820 KB |
testcase_10 | AC | 9 ms
12,992 KB |
testcase_11 | AC | 10 ms
11,900 KB |
testcase_12 | AC | 11 ms
13,256 KB |
testcase_13 | AC | 9 ms
12,496 KB |
testcase_14 | AC | 10 ms
12,108 KB |
testcase_15 | AC | 11 ms
12,992 KB |
testcase_16 | AC | 10 ms
13,252 KB |
testcase_17 | AC | 10 ms
11,840 KB |
testcase_18 | AC | 10 ms
12,448 KB |
testcase_19 | AC | 10 ms
13,512 KB |
testcase_20 | AC | 9 ms
12,016 KB |
testcase_21 | AC | 10 ms
11,960 KB |
testcase_22 | AC | 10 ms
11,960 KB |
testcase_23 | AC | 98 ms
52,560 KB |
testcase_24 | AC | 98 ms
53,072 KB |
testcase_25 | AC | 123 ms
52,820 KB |
testcase_26 | AC | 120 ms
51,676 KB |
testcase_27 | AC | 108 ms
52,948 KB |
testcase_28 | AC | 98 ms
51,536 KB |
testcase_29 | AC | 125 ms
51,280 KB |
testcase_30 | AC | 107 ms
51,924 KB |
testcase_31 | AC | 112 ms
52,692 KB |
testcase_32 | AC | 111 ms
51,788 KB |
testcase_33 | AC | 97 ms
51,540 KB |
testcase_34 | AC | 114 ms
52,944 KB |
testcase_35 | AC | 99 ms
52,052 KB |
testcase_36 | AC | 112 ms
52,564 KB |
testcase_37 | AC | 97 ms
53,072 KB |
testcase_38 | AC | 121 ms
51,924 KB |
testcase_39 | AC | 123 ms
52,944 KB |
testcase_40 | AC | 127 ms
51,408 KB |
testcase_41 | AC | 99 ms
51,792 KB |
testcase_42 | AC | 124 ms
51,408 KB |
testcase_43 | AC | 11 ms
12,188 KB |
testcase_44 | AC | 11 ms
13,760 KB |
testcase_45 | AC | 12 ms
12,624 KB |
testcase_46 | AC | 12 ms
12,768 KB |
testcase_47 | AC | 11 ms
12,136 KB |
testcase_48 | AC | 12 ms
12,020 KB |
testcase_49 | AC | 12 ms
13,384 KB |
testcase_50 | AC | 11 ms
11,940 KB |
testcase_51 | AC | 12 ms
11,848 KB |
testcase_52 | AC | 12 ms
12,996 KB |
testcase_53 | AC | 12 ms
12,200 KB |
testcase_54 | AC | 12 ms
12,516 KB |
testcase_55 | AC | 11 ms
12,632 KB |
testcase_56 | AC | 13 ms
13,120 KB |
testcase_57 | AC | 12 ms
11,808 KB |
testcase_58 | AC | 12 ms
12,520 KB |
testcase_59 | AC | 11 ms
11,816 KB |
testcase_60 | AC | 12 ms
12,996 KB |
testcase_61 | AC | 12 ms
13,124 KB |
testcase_62 | AC | 12 ms
12,556 KB |
testcase_63 | AC | 69 ms
12,156 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[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; }