結果

問題 No.1354 Sambo's Treasure
ユーザー chocoruskchocorusk
提出日時 2021-01-21 02:35:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,624 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 139,480 KB
実行使用メモリ 15,128 KB
最終ジャッジ日時 2023-08-25 13:25:41
合計ジャッジ時間 9,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,092 KB
testcase_01 AC 3 ms
7,888 KB
testcase_02 AC 3 ms
7,928 KB
testcase_03 AC 4 ms
8,084 KB
testcase_04 AC 3 ms
8,200 KB
testcase_05 AC 4 ms
7,956 KB
testcase_06 AC 3 ms
7,948 KB
testcase_07 AC 3 ms
7,772 KB
testcase_08 AC 4 ms
7,944 KB
testcase_09 AC 4 ms
7,880 KB
testcase_10 AC 3 ms
7,952 KB
testcase_11 AC 4 ms
8,028 KB
testcase_12 AC 3 ms
7,916 KB
testcase_13 AC 3 ms
7,924 KB
testcase_14 AC 3 ms
7,920 KB
testcase_15 AC 4 ms
7,944 KB
testcase_16 AC 4 ms
8,196 KB
testcase_17 AC 4 ms
8,056 KB
testcase_18 AC 4 ms
7,976 KB
testcase_19 AC 4 ms
8,200 KB
testcase_20 AC 3 ms
7,924 KB
testcase_21 AC 3 ms
7,952 KB
testcase_22 AC 4 ms
7,924 KB
testcase_23 AC 72 ms
14,852 KB
testcase_24 AC 71 ms
14,816 KB
testcase_25 AC 113 ms
14,824 KB
testcase_26 AC 115 ms
14,784 KB
testcase_27 AC 92 ms
14,848 KB
testcase_28 AC 72 ms
14,796 KB
testcase_29 AC 121 ms
14,824 KB
testcase_30 AC 93 ms
14,816 KB
testcase_31 AC 94 ms
14,796 KB
testcase_32 AC 93 ms
14,832 KB
testcase_33 AC 70 ms
14,800 KB
testcase_34 AC 94 ms
14,912 KB
testcase_35 AC 72 ms
14,784 KB
testcase_36 AC 96 ms
15,044 KB
testcase_37 AC 71 ms
14,868 KB
testcase_38 AC 113 ms
14,780 KB
testcase_39 AC 117 ms
14,880 KB
testcase_40 AC 118 ms
15,096 KB
testcase_41 AC 72 ms
15,044 KB
testcase_42 AC 113 ms
14,784 KB
testcase_43 AC 49 ms
14,096 KB
testcase_44 AC 48 ms
14,024 KB
testcase_45 AC 53 ms
14,328 KB
testcase_46 AC 59 ms
14,188 KB
testcase_47 AC 59 ms
14,004 KB
testcase_48 AC 68 ms
14,308 KB
testcase_49 AC 51 ms
14,144 KB
testcase_50 AC 52 ms
14,024 KB
testcase_51 AC 65 ms
14,008 KB
testcase_52 AC 60 ms
14,156 KB
testcase_53 AC 62 ms
14,328 KB
testcase_54 AC 54 ms
14,132 KB
testcase_55 AC 50 ms
14,052 KB
testcase_56 AC 65 ms
14,204 KB
testcase_57 AC 60 ms
14,404 KB
testcase_58 AC 61 ms
14,048 KB
testcase_59 AC 56 ms
14,044 KB
testcase_60 AC 63 ms
14,392 KB
testcase_61 AC 54 ms
14,052 KB
testcase_62 AC 66 ms
14,508 KB
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n, m, L, K; cin>>n>>m>>L>>K;
    fac(2*n);
    int xc[100010], yc[100010], xt[102], yt[102];
    xc[0]=yc[0]=0, xc[m+1]=yc[m+1]=n;
    for(int i=1; i<=m; i++){
        cin>>xc[i]>>yc[i];
    }
    vector<int> v[100010];
    for(int i=0; i<L; i++){
        cin>>xt[i]>>yt[i];
        for(int j=0; j<=m; j++){
            if(xc[j]<=xt[i] && xt[i]<=xc[j+1] && yc[j]<=yt[i] && yt[i]<=yc[j+1]){
                v[j].push_back(i);
                break;
            }
        }
    }
    ll dp0[102]={};
    dp0[0]=1;
    for(int i=0; i<=m; i++){
        if(v[i].empty()){
            for(int j=0; j<=min(L, K); j++) (dp0[j]*=comb(xc[i+1]-xc[i]+yc[i+1]-yc[i], xc[i+1]-xc[i]))%=MOD;
            continue;
        }
        sort(v[i].begin(), v[i].end(), [&](int i, int j){ return P(xt[i], yt[i])<P(xt[j], yt[j]);});
        int x1[102], y1[102];
        int l1=v[i].size();
        for(int j=0; j<l1; j++){
            x1[j+1]=xt[v[i][j]],y1[j+1]=yt[v[i][j]];
        }
        x1[0]=xc[i],y1[0]=yc[i],x1[l1+1]=xc[i+1],y1[l1+1]=yc[i+1];
        ll dp[2][102]={}, dp1[102][102]={};
        ll c[102][102]={};
        for(int j=0; j<=l1; j++){
            for(int k=j+1; k<=l1+1; k++){
                if(!(x1[j]<=x1[k] && y1[j]<=y1[k])) continue;
                for(int p=j; p<=k; p++) for(int q=0; q<2; q++) dp[q][p]=0;
                dp[0][j]=1;
                for(int p=j+1; p<=k; p++){
                    int p1=v[i][p];
                    for(int q=j; q<p; q++){
                        int q1=v[i][q];
                        for(int r=0; r<2; r++){
                            dp[r][p]+=dp[r^1][q]*comb(x1[p]-x1[q]+y1[p]-y1[q], x1[p]-x1[q]);
                            dp[r][p]%=MOD;
                        }
                    }
                }
                c[j][k]=(dp[1][k]-dp[0][k]+MOD)%MOD;
            }
        }
        dp1[0][0]=1;
        for(int p=1; p<=l1+1; p++){
            for(int j=1; j<=p; j++){
                for(int k=0; k<p; k++){
                    (dp1[p][j]+=dp1[k][j-1]*c[k][p])%=MOD;
                }
            }
        }
        ll ndp[102]={};
        for(int j=0; j<=min(K, L); j++){
            for(int k=0; k<=l1; k++){
                if(j+k<=min(K, L)){
                    (ndp[j+k]+=dp0[j]*dp1[l1+1][k+1])%=MOD;
                }
            }
        }
        for(int j=0; j<=min(K, L); j++){
            dp0[j]=ndp[j];
        }
    }
    ll ans=0;
    for(int i=0; i<=K; i++) (ans+=dp0[i])%=MOD;
    cout<<ans<<endl;

    return 0;
}
0