結果

問題 No.1214 Market
ユーザー chocoruskchocorusk
提出日時 2020-09-28 10:03:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,673 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 140,392 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2023-09-14 03:24:00
合計ジャッジ時間 16,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
template<int MOD>
struct ModInt{
	int x;
	ModInt(): x(0){}
	ModInt(ll y): x(y>=0 ? y%MOD : (MOD-(-y)%MOD)%MOD){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=MOD) x-=MOD;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=MOD-p.x)>=MOD) x-=MOD;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1ll*x*p.x%MOD);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inv();
		return *this;
	}

	ModInt operator-() const{ return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{ return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p) const{ return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p) const{ return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p) const{ return ModInt(*this)/=p;}
	bool operator==(const ModInt &p) const{ return x==p.x;}
	bool operator!=(const ModInt &p) const{ return x!=p.x;}

	ModInt pow(ll n) const{
		ModInt ret(1), p(x);
		while(n){
			if(n&1) ret*=p;
			p*=p;
			n>>=1;
		}
		return ret;
	}
	ModInt inv() const{
		return pow(MOD-2);
	}
};
const int MOD=1e9+7;
using mint=ModInt<MOD>;
mint dp0[41][41];
mint f[41], invf[41];
int main()
{
    int n, m, k;
    cin>>n>>m>>k;
    f[0]=invf[0]=mint(1);
    for(int i=1; i<=n; i++) f[i]=f[i-1]*mint(i), invf[i]=f[i].inv();
    dp0[0][0]=mint(1);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int l=1; l<=j; l++){
                dp0[i][j]+=dp0[i-1][j-l]*invf[l];
            }
        }
    }
    auto comb=[&](int x, int y){
        if(!(0<=y && y<=x)) return mint(0);
        mint res=invf[y];
        for(int i=0; i<y; i++){
            res*=mint(x-i);
        }
        return res;
    };
    auto calc=[&](int x, int l){
        mint res(0);
        for(int i=0; i<=l; i++){
            res+=dp0[i][l]*comb(x, i);
        }
        return res;
    };
    int a[41], b[41];
    map<int, vector<int>> mp;
    for(int i=0; i<m; i++) cin>>a[i]>>b[i];
    for(int i=0; i<m; i++){
        mp[a[i]].push_back(b[i]);
    }
    int a1[41];
    int z=0;
    for(auto p:mp) a1[z++]=p.first;
    a1[z]=k+1;
    mint ans(0);
    for(int t=0; t<m; t++){
        int b0=b[t];
        int m1=mp.size();
        mint dp[41][41][41];
        dp[0][0][0]=mint(1);
        for(int i=0; i<=n; i++) dp[0][i][0]=calc(a1[0], i);
        bool myon=0;
        for(int i=0; i<m1; i++){
            auto v=mp[a1[i]];
            int c=0;
            for(auto x:v){
                if(x>b0) c++;
                else if(x==b0) myon=1;
            }
            for(int j=0; j<=n; j++){
                for(int l=0; l<=n; l++){
                    if(dp[i][j][l].x==0) continue;
                    for(int p=0; p<=n-j; p++){
                        if(myon && l+c-p<0) continue;
                        dp[i+1][j+p][max(0, l+c-p)]+=dp[i][j][l]*calc(a1[i+1]-a1[i], p);
                    }
                }
            }
        }
        for(int i=0; i<=n; i++) ans+=dp[m1][n][i]*f[n]*mint(b0);
    }
    mint s(0);
    for(int i=0; i<m; i++){
        s+=mint(b[i]);
    }
    mint tot=mint(k+1).pow(n);
    s*=tot;
    ans=(s-ans)/tot;
    cout<<ans.x<<endl;
    return 0;
}
0