結果

問題 No.1354 Sambo's Treasure
ユーザー chocoruskchocorusk
提出日時 2021-01-21 02:47:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 3,555 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 138,032 KB
実行使用メモリ 15,112 KB
最終ジャッジ日時 2023-08-25 13:48:09
合計ジャッジ時間 8,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,992 KB
testcase_01 AC 3 ms
8,264 KB
testcase_02 AC 3 ms
7,984 KB
testcase_03 AC 3 ms
7,940 KB
testcase_04 AC 4 ms
8,116 KB
testcase_05 AC 3 ms
7,980 KB
testcase_06 AC 3 ms
8,096 KB
testcase_07 AC 3 ms
8,308 KB
testcase_08 AC 4 ms
8,132 KB
testcase_09 AC 3 ms
7,976 KB
testcase_10 AC 3 ms
7,932 KB
testcase_11 AC 3 ms
8,260 KB
testcase_12 AC 3 ms
8,168 KB
testcase_13 AC 3 ms
7,992 KB
testcase_14 AC 4 ms
7,996 KB
testcase_15 AC 3 ms
8,112 KB
testcase_16 AC 3 ms
8,336 KB
testcase_17 AC 4 ms
7,996 KB
testcase_18 AC 4 ms
7,940 KB
testcase_19 AC 3 ms
8,048 KB
testcase_20 AC 4 ms
8,064 KB
testcase_21 AC 4 ms
8,000 KB
testcase_22 AC 3 ms
7,776 KB
testcase_23 AC 73 ms
14,828 KB
testcase_24 AC 71 ms
14,884 KB
testcase_25 AC 116 ms
14,832 KB
testcase_26 AC 116 ms
14,844 KB
testcase_27 AC 93 ms
14,964 KB
testcase_28 AC 73 ms
14,832 KB
testcase_29 AC 120 ms
14,844 KB
testcase_30 AC 94 ms
14,904 KB
testcase_31 AC 96 ms
14,876 KB
testcase_32 AC 94 ms
15,032 KB
testcase_33 AC 71 ms
14,840 KB
testcase_34 AC 96 ms
14,964 KB
testcase_35 AC 72 ms
14,832 KB
testcase_36 AC 97 ms
14,960 KB
testcase_37 AC 72 ms
14,840 KB
testcase_38 AC 116 ms
15,036 KB
testcase_39 AC 118 ms
14,828 KB
testcase_40 AC 119 ms
14,884 KB
testcase_41 AC 72 ms
14,832 KB
testcase_42 AC 115 ms
15,112 KB
testcase_43 AC 50 ms
14,340 KB
testcase_44 AC 49 ms
14,400 KB
testcase_45 AC 54 ms
14,544 KB
testcase_46 AC 59 ms
14,608 KB
testcase_47 AC 57 ms
14,364 KB
testcase_48 AC 69 ms
14,264 KB
testcase_49 AC 53 ms
14,116 KB
testcase_50 AC 54 ms
14,072 KB
testcase_51 AC 68 ms
14,328 KB
testcase_52 AC 61 ms
14,264 KB
testcase_53 AC 64 ms
14,184 KB
testcase_54 AC 55 ms
14,380 KB
testcase_55 AC 51 ms
14,052 KB
testcase_56 AC 66 ms
14,060 KB
testcase_57 AC 61 ms
14,180 KB
testcase_58 AC 61 ms
14,384 KB
testcase_59 AC 57 ms
14,104 KB
testcase_60 AC 64 ms
14,072 KB
testcase_61 AC 54 ms
14,364 KB
testcase_62 AC 68 ms
14,128 KB
testcase_63 AC 115 ms
14,828 KB
権限があれば一括ダウンロードができます

ソースコード

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++){
                    for(int q=j; q<p; 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<=min(K, L); i++) (ans+=dp0[i])%=MOD;
    cout<<ans<<endl;
    return 0;
}
0