Submission #40733

#TimeUsernameProblemLanguageResultExecution timeMemory
40733Alexa2001Skyscraper (JOI16_skyscraper)C++14
100 / 100
468 ms4068 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 103, Kmax = 1003; const int Mod = 1e9 + 7; typedef long long ll; int N, K, i, j, k, F, S, new_k, a[Nmax]; int now[Nmax][Kmax][2][2], old[Nmax][Kmax][2][2]; void add_to(int &x, int y, int z) { x = (x + (ll)y*z) % Mod; } int main() { // freopen("input", "r", stdin); cin >> N >> K; for(i=1; i<=N; ++i) cin >> a[i]; sort(a+1, a+N+1); for(i=1; i<N; ++i) a[i] = a[i+1] - a[i]; now[0][0][1][1] = now[0][0][0][1] = now[0][0][1][0] = now[0][0][0][0] = 1; for(i=1; i<N; ++i) { memcpy(old, now, sizeof(now)); memset(now, 0, sizeof(now)); for(j=0; j<=N; ++j) for(k=0; k<=K; ++k) for(F=0; F<2; ++F) for(S=0; S<2; ++S) { new_k = k + a[i] * (2 * j + F + S); if(new_k > K) continue; add_to(now[j+1][new_k][F][S], j, old[j][k][F][S]); add_to(now[j][new_k][F][S], 2*j, old[j][k][F][S]); if(j) add_to(now[j-1][new_k][F][S], j, old[j][k][F][S]); if(F) { add_to(now[j+1][new_k][1][S], 1, old[j][k][F][S]); add_to(now[j][new_k][1][S], 1, old[j][k][F][S]); add_to(now[j+1][new_k][0][S], 1, old[j][k][F][S]); add_to(now[j][new_k][0][S], 1, old[j][k][F][S]); } if(S) { add_to(now[j+1][new_k][F][1], 1, old[j][k][F][S]); add_to(now[j][new_k][F][1], 1, old[j][k][F][S]); add_to(now[j+1][new_k][F][0], 1, old[j][k][F][S]); add_to(now[j][new_k][F][0], 1, old[j][k][F][S]); } } } int ans = 0; for(i=0; i<=K; ++i) add_to(ans, 1, now[0][i][0][0]); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...