結果

問題 No.1214 Market
ユーザー chocorusk
提出日時 2020-09-28 10:03:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,673 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 137,244 KB
最終ジャッジ日時 2025-01-14 23:12:47
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 19 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0