Submission #372809

#TimeUsernameProblemLanguageResultExecution timeMemory
372809MiricaMateiSkyscraper (JOI16_skyscraper)C++14
100 / 100
173 ms70124 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const int MAXL = 1005; const int MOD = 1e9 + 7; int a[MAXN]; int dp[MAXN][MAXN][MAXL][5]; int main() { //freopen("date.in", "r", stdin); //freopen("date.out", "w", stdout); int n, l; scanf("%d%d", &n, &l); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); dp[1][0][0][0] = 1; dp[1][0][0][1] = 2; dp[1][0][0][2] = 1; for (int i = 1; i < n; ++i) { int dif = a[i] - a[i + 1]; for (int j = 0; j <= i + 1; ++j) { for (int s = 0; s <= l; ++s) { for (int e = 0; e <= 2; ++e) { int ns = s + dif * (2 * j + 2 - e); if (ns > l) continue; if (j - 1 >= 0) dp[i + 1][j - 1][ns][e] = (dp[i + 1][j - 1][ns][e] + 1LL * j * dp[i][j][s][e]) % MOD; dp[i + 1][j][ns][e] = (dp[i + 1][j][ns][e] + 1LL * (2 * j + 2 - e) * dp[i][j][s][e]) % MOD; dp[i + 1][j + 1][ns][e] = (dp[i + 1][j + 1][ns][e] + 1LL * (j + 2 - e) * dp[i][j][s][e]) % MOD; if (e + 1 <= 2) dp[i + 1][j][ns][e + 1] = (dp[i + 1][j][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD; if (e + 1 <= 2) dp[i + 1][j + 1][ns][e + 1] = (dp[i + 1][j + 1][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD; } } } } int ans = 0; for (int i = 0; i <= l; ++i) ans = (ans + dp[n][0][i][2]) % MOD; printf("%d\n", ans); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d%d", &n, &l);
      |   ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...