Submission #1043799

#TimeUsernameProblemLanguageResultExecution timeMemory
1043799lozergamSkyscraper (JOI16_skyscraper)C++17
100 / 100
49 ms51024 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define For(i, n) for(int (i) = 0 ; (i) < (n); (i)++) #define debug(x) cout << #x << " : " << x << endl << flush #define endl '\n' #define sz(x) (ll)x.size() const ll MOD = 1e9 + 7; const ll maxn = 103; const ll maxl = 1005; ll dp[maxn][maxn][maxl][3]; ll a[maxn]; ll n, l; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin >> n >> l; for(int i = 1; i <= n; i++) cin >> a[i]; if(n == 1) { cout << 1 << endl; exit(0); } sort(a + 1, a + n + 1); a[n + 1] = 10000; dp[0][0][0][0] = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= i; j++) for(int k = 0; k <= l; k++) for(int m = 0; m <= 2; m++) { ll delta = (2 * j - m) * (a[i + 1] - a[i]); if(delta > k)continue; if(i + j + 1 - m > n)continue; //new element make a new comp and dont have end point dp[i][j][k][m] += dp[i - 1][j - 1][k - delta][m]; //new element make a new comp and have end point if(m == 1) dp[i][j][k][m] += 2 * dp[i - 1][j - 1][k - delta][0]; else if(m == 2) dp[i][j][k][m] += dp[i - 1][j - 1][k - delta][1]; //new element go to one of the comps but not the endpoint dp[i][j][k][m] += (2 * j - m) * dp[i - 1][j][k - delta][m]; //new element go to one of the comps and endpoint if(m == 1) dp[i][j][k][m] += (2 * j) * dp[i - 1][j][k - delta][0]; else if(m == 2 and i == n) dp[i][j][k][m] += dp[i - 1][j][k - delta][1]; else if(m == 2) dp[i][j][k][m] += (j - 1) * dp[i - 1][j][k - delta][1]; //new element combone two comps if(m == 0) dp[i][j][k][m] += (j * (j + 1)) * dp[i - 1][j + 1][k - delta][0]; else if(m == 1) dp[i][j][k][m] += (j * (j - 1) + j) * dp[i - 1][j + 1][k - delta][1]; else if(i == n) dp[i][j][k][m] += dp[i - 1][j + 1][k - delta][2]; else dp[i][j][k][m] += ((2 * (j - 1)) + ((j - 1) * (j - 2))) * dp[i - 1][j + 1][k - delta][2]; dp[i][j][k][m] %= MOD; } ll ans = 0; For(i, l+1)ans += dp[n][1][i][2]; cout << ans % MOD << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n); (i)++)
      |                           ^
skyscraper.cpp:85:2: note: in expansion of macro 'For'
   85 |  For(i, l+1)ans += dp[n][1][i][2];
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...