結果

問題 No.1214 Market
ユーザー msm1993msm1993
提出日時 2020-10-08 10:18:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 2,219 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 184,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 11:43:45
合計ジャッジ時間 8,680 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 336 ms
4,380 KB
testcase_09 AC 331 ms
4,380 KB
testcase_10 AC 328 ms
4,380 KB
testcase_11 AC 341 ms
4,376 KB
testcase_12 AC 374 ms
4,380 KB
testcase_13 AC 355 ms
4,376 KB
testcase_14 AC 359 ms
4,380 KB
testcase_15 AC 354 ms
4,380 KB
testcase_16 AC 361 ms
4,384 KB
testcase_17 AC 357 ms
4,380 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 55 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 256 ms
4,380 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 13 ms
4,376 KB
testcase_26 AC 95 ms
4,376 KB
testcase_27 AC 32 ms
4,376 KB
testcase_28 AC 196 ms
4,380 KB
testcase_29 AC 22 ms
4,376 KB
testcase_30 AC 34 ms
4,380 KB
testcase_31 AC 8 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 123 ms
4,384 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 20 ms
4,376 KB
testcase_36 AC 61 ms
4,380 KB
testcase_37 AC 146 ms
4,380 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using ll=long long;
using std::cin;
using std::cout;
using std::endl;
using std::vector;
const ll MOD=1e9+7;
const ll MAX=1e4;
ll modpow(ll X,ll Y){
    ll ret=1;
    while(Y){
        if(Y%2) ret=ret*X%MOD;
        X=X*X%MOD;
        Y/=2;
    }
    return ret;
}
ll fac[MAX],finv[MAX];
void COMinit(){
    fac[0]=fac[1]=finv[0]=finv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        finv[i]=finv[i-1]*modpow(i,MOD-2)%MOD;
    }
}
ll COM(ll N,ll R){
    if(N<0||R<0||N<R) return 0;
    return fac[N]*finv[R]%MOD*finv[N-R]%MOD;
}
int main(){
    COMinit();
    ll N,M,K; cin>>N>>M>>K;
    vector<ll> A(M),B(M);//値段がA,価値がB
    ll ans=0;
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
    }
    for(int i=0;i<M;i++){
        if(K<A[i]) continue;
        vector<ll> S,cnt;//集合S
        std::map<ll,ll> memo;
        ll len2=0;
        for(int j=0;j<M;j++){
            if(B[j]>=B[i]&&A[j]<=K){
                memo[A[j]]++;
                len2++;
            }
        }
        for(auto p:memo){
            S.push_back(p.first);
            cnt.push_back(p.second);
        }
        S.push_back(K+1);//番兵
        ll len=S.size();
        vector<vector<vector<ll>>> dp(len,vector<vector<ll>>(len2+1,vector<ll>(N+1)));//見てる品物,残りの品物,残りの人
        for(int j=0;j<=N;j++){
            dp[0][0][N-j]=COM(N,j)*modpow(S[0],j)%MOD;
        }
        for(int j=0;j<len-1;j++){
            for(int k=0;k<=len2;k++){
                for(int l=0;l<=N;l++){
                    for(int m=0;m<=l;m++){
                        if((S[j]>=A[i]&&k-m+cnt[j]<=0)||k-m+cnt[j]>len2) continue;
                        dp[j+1][std::max(0ll,k-m+cnt[j])][l-m]+=dp[j][k][l]*COM(l,m)%MOD*modpow(S[j+1]-S[j],m)%MOD;
                        dp[j+1][std::max(0ll,k-m+cnt[j])][l-m]%=MOD;
                    }
                }
            }
        }
        ll sum=0;
        for(int j=1;j<=len2;j++){
            sum+=dp[len-1][j][0];
            sum%=MOD;
        }
        sum=modpow(K+1,N)-sum;
        if(sum<0) sum+=MOD;
        ans+=sum*B[i]%MOD;
        ans%=MOD;
    }
    ans*=modpow(modpow(K+1,N),MOD-2);
    ans%=MOD;
    cout<<ans<<endl;
}
0