結果

問題 No.1354 Sambo's Treasure
ユーザー blackyukiblackyuki
提出日時 2021-01-17 11:25:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,889 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 217,996 KB
実行使用メモリ 21,352 KB
最終ジャッジ日時 2024-05-07 01:29:04
合計ジャッジ時間 7,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 86 ms
21,300 KB
testcase_24 AC 83 ms
21,312 KB
testcase_25 AC 150 ms
21,148 KB
testcase_26 AC 135 ms
21,132 KB
testcase_27 AC 91 ms
21,208 KB
testcase_28 AC 82 ms
21,292 KB
testcase_29 WA -
testcase_30 AC 103 ms
21,248 KB
testcase_31 AC 100 ms
21,156 KB
testcase_32 AC 99 ms
21,212 KB
testcase_33 AC 83 ms
21,124 KB
testcase_34 AC 103 ms
21,224 KB
testcase_35 AC 84 ms
21,240 KB
testcase_36 AC 99 ms
21,168 KB
testcase_37 AC 82 ms
21,352 KB
testcase_38 AC 138 ms
21,124 KB
testcase_39 AC 140 ms
21,280 KB
testcase_40 AC 135 ms
21,132 KB
testcase_41 AC 81 ms
21,128 KB
testcase_42 AC 138 ms
21,156 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 138 ms
21,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=998244353;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
vi fac,finv,inv;
void init(ll n){
    n*=3;
    fac=vi(n+5);finv=vi(n+5);inv=vi(n+5);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    REP(i,2,n+5){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
long long modcom(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll f(P a,P b){return modcom(b.fi-a.fi+b.se-a.se,b.se-a.se);}
int main(){
    ll n,m,l,k;cin>>n>>m>>l>>k;init(n);
    vp checkpoint(m+2);checkpoint[0]=P(0,0);checkpoint[m+1]=P(n,n);
    rep(i,m)cin>>checkpoint[i+1].fi>>checkpoint[i+1].se;
    vvp tiger(m+1);
    ll cnt_tiger=0;
    rep(i,l){
        ll x,y;cin>>x>>y;
        ll t=lb(checkpoint,P(x,y));
        if(checkpoint[t]==P(x,y))k--;
        else if(checkpoint[t-1].se<=y&&y<=checkpoint[t].se){
            tiger[t-1].pb(x,y);
            cnt_tiger++;
        }
    }
    l=cnt_tiger;
    chmin(k,l);
    if(k<0)dame(0);
    vi dp(k+1,1);
    rep(i,m+1){
        vvi ndp(tiger[i].size(),vi(k+2));
        rep(j,ndp.size())rep(t,k+1){
            ndp[j][t+1]=dp[t]*f(checkpoint[i],tiger[i][j]);
            rep(u,j)ndp[j][t+1]-=(ndp[u][t+1]-ndp[u][t])*f(tiger[i][u],tiger[i][j]);
            ndp[j][t+1]%=mod;
            ndp[j][t+1]+=mod;
            ndp[j][t+1]%=mod;
        }
        vi tmp(k+1);
        rep(j,k+1){
            tmp[j]=dp[j]*f(checkpoint[i],checkpoint[i+1]);
            rep(u,ndp.size()){
                tmp[j]-=(ndp[u][j+1]-ndp[u][j])*f(tiger[i][u],checkpoint[i+1]);
            }
            tmp[j]%=mod;
            tmp[j]+=mod;
            tmp[j]%=mod;
        }
        dp=tmp;
    }
    out(dp[k]);
}
0