Submission #221652

#TimeUsernameProblemLanguageResultExecution timeMemory
221652ryanseeSkyscraper (JOI16_skyscraper)C++14
100 / 100
695 ms146424 KiB
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } typedef long long ll; typedef long double ld; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi; #define LLINF ((long long)1e18) #define INF int(1e9+1e6) #define MAXN (106) ll n,L,dp[106][106][2][2][1006],A[106],mod=1e9+7; int main(){ FAST cin>>n>>L; FOR(i,1,n)cin>>A[i]; sort(A+1,A+n+1); if(n==1){ return cout<<1, 0; } if(n==2){ if(A[2]-A[1] <= L) return cout<<2, 0; else return cout<<0, 0; } dp[0][0][0][0][0]=1; FOR(i,1,n-1)FOR(c,1,i)FOR(s,0,1)FOR(e,0,1)FOR(l,0,L){ ll diff=A[i]-A[i-1]; if(l-diff*((c+1-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c+1][s][e][l-diff*((c+1-s-e)*2+s+e)] * (((c+1) * c - (e?c:0) - (s?c:0))%mod)%mod,dp[i][c][s][e][l]%=mod; // +(s&&e)-(s&&e) if(l-diff*((c-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c][s][e][l-diff*((c-s-e)*2+s+e)] * ((c-s-e)*2+s+e) % mod, dp[i][c][s][e][l]%=mod; if(l-diff*((c-1-s-e)*2+s+e)>=0) dp[i][c][s][e][l] += dp[i-1][c-1][s][e][l-diff*((c-1-s-e)*2+s+e)], dp[i][c][s][e][l]%=mod; if(s) { if(l-diff*((c-e)*2+e)>=0)dp[i][c][s][e][l] += dp[i-1][c][0][e][l-diff*((c-e)*2+e)] * (c-e) % mod, dp[i][c][s][e][l]%=mod; if(l-diff*((c-1-e)*2+e)>=0)dp[i][c][s][e][l] += dp[i-1][c-1][0][e][l-diff*((c-1-e)*2+e)] % mod, dp[i][c][s][e][l]%=mod; } if(e) { if(l-diff*((c-s)*2+s)>=0) dp[i][c][s][e][l] += dp[i-1][c][s][0][l-diff*((c-s)*2+s)] * (c-s) % mod, dp[i][c][s][e][l]%=mod; if(l-diff*((c-1-s)*2+s)>=0) dp[i][c][s][e][l] += dp[i-1][c-1][s][0][l-diff*((c-1-s)*2+s)] % mod, dp[i][c][s][e][l]%=mod; } // cerr<<i<<' '<<c<<' '<<s<<' '<<e<<' '<<l<<": "<<dp[i][c][s][e][l]<<'\n'; } ll ans=0; // i=n-1, c=2, s=1, e=1, l += diff * 2 // i=n-1, c=1, s=1, e=0, l += diff // i=n-1, c=1, s=0, e=1, l += diff FOR(l,0,L){ ll diff=A[n]-A[n-1]; if(l-diff*2>=0) ans+=dp[n-1][2][1][1][l-diff*2],ans%=mod; if(l-diff>=0) ans+=dp[n-1][1][1][0][l-diff]+dp[n-1][1][0][1][l-diff],ans%=mod; } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...