#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int MOD = 998244353;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mid (l+(r-l)/2)
using ll = long long;
using ld = long double;
using str = string;
using i128 = __int128;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pd = pair<ld,ld>;
#define f first
#define s second
#define cf cout<<flush
template <class T> using V = vector<T>;
using vi = V<int>;
using vvi = V<vi>;
using vl = V<ll>;
using vvl = V<vl>;
using vd = V<ld>;
using vpi = V<pii>;
using vpl = V<pll>;
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x)),reverse(all(x))
#define uniq(x) sor(x), x.resize(unique(all(x))-x.begin())
#define pb push_back
#define ft front()
#define bk back()
#define chmi(x,y, ...) x = min(__VA_OPT__({) x,y __VA_OPT__(,)__VA_ARGS__ __VA_OPT__(}))
#define chma(x,y, ...) x = max(__VA_OPT__({) x,y __VA_OPT__(,)__VA_ARGS__ __VA_OPT__(}))
#define lwb(x,y) (int)(lower_bound(all(x),y)-x.begin())
#define upb(x,y) (int)(upper_bound(all(x),y)-x.begin())
#define compress(v) {auto _t=v;uniq(_t);for(auto &x:v)x=lwb(_t,x);}
#define in(x,y,n,m) (x>=0&&x<n&&y>=0&&y<m)
#define retu(args, ...) {ps(args __VA_OPT__(,)__VA_ARGS__);return ;}
#define For(i,a,b) for(int i = (a); i <= (b); i++)
#define F0r(i,a) for(int i = 0; i < (a); i++)
#define Rof(i,a,b) for(int i = (b); i >= (a); i--)
#define R0f(i,a) for(int i = (a)-1; i >= 0; i--)
#define rep(a) F0r(_,a)
#define each(a,x) for(auto &a:x)
const int dx[4]{1,0,-1,0},dy[4]{0,1,0,-1};
const int dx8[8]{1,1,0,-1,-1,-1,0,1},dy8[8]{0,1,1,1,0,-1,-1,-1};
template <class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
constexpr int pct(int x){return __builtin_popcount(x);}
constexpr int pctll(long long x){return __builtin_popcountll(x);}
constexpr int bits(int x){return 31-__builtin_clz(x);}
#define SFINAE(x, ...) \
template <class, class = void> struct x : std::false_type {}; \
template <class T> struct x<T, std::void_t<__VA_ARGS__>> : std::true_type {}
SFINAE(DefaultI, decltype(std::cin >> std::declval<T &>()));
SFINAE(DefaultO, decltype(std::cout << std::declval<T &>()));
SFINAE(IsTuple, typename std::tuple_size<T>::type);
SFINAE(Iterable, decltype(std::begin(std::declval<T>())));
template <auto &is> struct Reader {
template <class T> void Impl(T &t) {
if constexpr (DefaultI<T>::value) is >> t;
else if constexpr (Iterable<T>::value) {
for (auto &x : t) Impl(x);
} else if constexpr (IsTuple<T>::value) {
std::apply([this](auto &...args) { (Impl(args), ...); }, t);
} else static_assert(IsTuple<T>::value, "No matching type for read");
}
template <class... Ts> void read(Ts &...ts) { ((Impl(ts)), ...); }
};
template <class... Ts> void re(Ts &...ts) { Reader<cin>{}.read(ts...); }
#define def(t, args...) \
t args; \
re(args);
template <auto &os, bool debug, bool print_nd> struct Writer {
string comma() const { return debug ? "," : ""; }
template <class T> constexpr char Space(const T &) const {
return print_nd && (Iterable<T>::value or IsTuple<T>::value) ? '\n'
: ' ';
}
template <class T> void Impl(T const &t) const {
if constexpr (DefaultO<T>::value) os << t;
else if constexpr (Iterable<T>::value) {
if (debug) os << '{';
int i = 0;
for (auto &&x : t)
((i++) ? (os << comma() << Space(x), Impl(x)) : Impl(x));
if (debug) os << '}';
} else if constexpr (IsTuple<T>::value) {
if (debug) os << '(';
std::apply(
[this](auto const &...args) {
int i = 0;
(((i++) ? (os << comma() << " ", Impl(args)) : Impl(args)),
...);
},
t);
if (debug) os << ')';
} else static_assert(IsTuple<T>::value, "No matching type for print");
}
template <class T> void ImplWrapper(T const &t) const {
if (debug) os << "\033[0;31m";
Impl(t);
if (debug) os << "\033[0m";
}
template <class... Ts> void print(Ts const &...ts) const {
((Impl(ts)), ...);
}
template <class F, class... Ts>
void print_with_sep(const std::string &sep, F const &f,
Ts const &...ts) const {
ImplWrapper(f), ((os << sep, ImplWrapper(ts)), ...), os << '\n';
}
void print_with_sep(const std::string &) const { os << '\n'; }
};
template <class... Ts> void pr(Ts const &...ts) {
Writer<cout, false, true>{}.print(ts...);
}
template <class... Ts> void ps(Ts const &...ts) {
Writer<cout, false, true>{}.print_with_sep(" ", ts...);
}
void setIn(str s) { freopen(s.c_str(), "r", stdin); }
void setOut(str s) { freopen(s.c_str(), "w", stdout); }
void setIO(str s = "") {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(12);
if (sz(s)) setIn(s + ".in"), setOut(s + ".out");
}
struct mint {
static int mod;
int v;
explicit operator int() const {
return v;
} // explicit -> don't silently convert to int
mint() : v(0) {}
mint(ll _v) {
v = int((-mod < _v && _v < mod) ? _v : _v % mod);
if (v < 0) v += mod;
}
bool operator==(const mint &o) const { return v == o.v; }
friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
friend bool operator<(const mint &a, const mint &b) { return a.v < b.v; }
friend istream &operator>>(istream &is, mint &a) {
ll x;
is >> x;
a = mint(x);
return is;
}
friend ostream &operator<<(ostream &os, mint a) {
os << int(a);
return os;
}
mint &operator+=(const mint &o) {
if ((v += o.v) >= mod) v -= mod;
return *this;
}
mint &operator-=(const mint &o) {
if ((v -= o.v) < 0) v += mod;
return *this;
}
mint &operator*=(const mint &o) {
v = int((ll)v * o.v % mod);
return *this;
}
mint &operator/=(const mint &o) { return (*this) *= inverse(o); }
friend mint pow(mint a, ll p) {
mint ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1) ans *= a;
return ans;
}
friend mint inverse(const mint &a) {
assert(a.v != 0);
return pow(a, mod - 2);
}
mint operator-() const { return mint(-v); }
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint &b) { return a += b; }
friend mint operator-(mint a, const mint &b) { return a -= b; }
friend mint operator*(mint a, const mint &b) { return a *= b; }
friend mint operator/(mint a, const mint &b) { return a /= b; }
};
int mint::mod = 1e9+7;
using mi = mint;
using vmi = V<mi>;
using pmi = pair<mi, mi>;
using vpmi = V<pmi>;
//#include<atcoder/all>
//using namespace atcoder;
#define N 200005
mi dp[101][1001][3],t[101][1001][3];
void solve(){
def(int,n,m);
vi a(n);
re(a);
if(n==1)retu(0);
sor(a);
int last=a[0];
dp[1][0][0]=1;
dp[1][0][1]=2;
For(i,1,n-1){
int x=a[i]-last;
F0r(j,101)F0r(k,1001)F0r(l,3)t[j][k][l]=0;
F0r(j,n)For(k,0,m)F0r(l,3){
int val=k+(j*2-l)*x;
if(val<=m){
t[j+1][val][l]+=dp[j][k][l];
if(l<2)t[j+1][val][l+1]+=dp[j][k][l]*(2-l);
t[j][val][l]+=dp[j][k][l]*(j*2-l);
if(l==0)t[j][val][l+1]+=dp[j][k][l]*2*j;
else if(l==1){
if(j>1){
t[j][val][l+1]+=dp[j][k][l]*(j-1);
}
else if(j==1&&i==n-1){
t[j][val][l+1]+=dp[j][k][l];
}
}
if(j>1){
if(l==0)t[j-1][val][l]+=dp[j][k][l]*j*(j-1);
else if(l==1)t[j-1][val][l]+=dp[j][k][l]*(j-1)*(j-1);
else{
t[j-1][val][l]+=dp[j][k][l]*(j-2)*(j-3);
t[j-1][val][l]+=dp[j][k][l]*(2*j-4);
if(i==n-1&&j==2)t[j-1][val][l]+=dp[j][k][l];
}
}
}
}
last=a[i];
swap(dp,t);
}
mi ans=0;
F0r(i,m+1)ans+=dp[1][i][2];
ps(ans);
return ;
}
int main(){
setIO();
int t=1;
//re(t);
while(t--)solve();
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'void setIn(str)':
skyscraper.cpp:138:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
138 | void setIn(str s) { freopen(s.c_str(), "r", stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'void setOut(str)':
skyscraper.cpp:139:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
139 | void setOut(str s) { freopen(s.c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |