Submission #1150131

#TimeUsernameProblemLanguageResultExecution timeMemory
1150131nai0610Skyscraper (JOI16_skyscraper)C++20
15 / 100
103 ms260552 KiB
#include <bits/stdc++.h>
#define ll int64_t
#define ld long double
using namespace std;
// 
const int maxn =1e2+5;
const int mod = 1e9+7; // 998244353,1610612741
const ll inf = 1e18;
const ld pi = atan(1.0L)*4;
template <ll mod = 1000000007>
struct ModInt{
    ll p;
 
    ModInt() : p(0){}
    ModInt(ll x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}
 
    ModInt& operator+=(const ModInt& y) {
        p = (p + y.p) % mod;
        return *this;
    }
    ModInt& operator-=(const ModInt& y) {
        p = (p - y.p + mod) % mod;
        return *this;
    }
    ModInt& operator*=(const ModInt& y) {
        p = (p * y.p) % mod;
        return *this;
    }
    ModInt& operator%=(const ModInt& y) {
        if (y.p != 0) p %= y.p;
        return *this;
    }
 
    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}
 
    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }
 
    friend istream& operator>>(istream& stream, ModInt<mod>& x) {
        ll val;
        stream >> val;
        x = ModInt(val);
        return stream;
    }
 
    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}
 
    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}
 
    const ll& operator*() const{return p;}
    ll& operator*(){return p;}
 
};
 
using mint = ModInt<1000000007>;
int n,K,a[maxn];
mint f[maxn][maxn][1005][3];
int main() {
    // freopen("../input.inp","r",stdin);
    // freopen("output.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    clock_t start,end;
	start=clock();
	cin >>n>>K;
	for (int i=1;i<=n;i++) cin >>a[i];
	sort(a+1,a+1+n);
	a[n+1]=mod;
	f[0][0][0][0]=1;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++) {
			for (int k=0;k<=K;k++) {
				for (int m=0;m<=2;m++) {
					int d=(2*j-m)*(a[i+1]-a[i]);
					if (d>k||i+j+1-m>n) continue;
					f[i][j][k][m]=f[i-1][j-1][k-d][m]+f[i-1][j][k-d][m]*(2*j-m);
					if (m) {
						f[i][j][k][m]+=f[i-1][j-1][k-d][m-1]*(3-m);
						if (m==1) f[i][j][k][m]+=f[i-1][j][k-d][m-1]*2*j;
						else if (m==2) {
							if (i==n) f[i][j][k][m]+=f[i-1][j][k-d][m-1];
							else f[i][j][k][m]+=f[i-1][j][k-d][m-1]*(j-1);
						}
					}
					if (m==2) {
						if (i==n) f[i][j][k][m]+=f[i-1][j+1][k-d][m];
						else f[i][j][k][m]+=f[i-1][j+1][k-d][m]*j*(j-1);
					}
					else if (m==1) f[i][j][k][m]+=f[i-1][j+1][k-d][m]*j*j;
					else f[i][j][k][m]+=f[i-1][j+1][k-d][m]*j*(j+1);
				}
			}
		}
	}
	mint res=0;
	for (int i=1;i<=K;i++) res+=f[n][1][i][2];
	cout<<res;
	end=clock();	
	ld dur=(ld)(end-start)/(ld)(CLOCKS_PER_SEC)*(1000.0L);
	cerr<<dur;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...