Submission #860952

#TimeUsernameProblemLanguageResultExecution timeMemory
860952blackslexSkyscraper (JOI16_skyscraper)C++17
100 / 100
104 ms98384 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 105, L = 1005, M = 1e9 + 7; ll n, d, a[N], dp[N][N][L][3]; int main() { scanf("%lld %lld", &n, &d); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + n + 1); dp[1][1][0][0] = 1; dp[1][1][0][1] = 2; for (int i = 1; i < n; i++) { for (int j = 1; j <= i; j++) { for (int l = 0; l <= d; l++) { for (int k = 0; k < 3; k++) { int cur = l + (a[i + 1] - a[i]) * (j * 2LL - k); if (cur > d) continue; dp[i + 1][j - 1][cur][k] += (j - 1LL) * dp[i][j][l][k]; dp[i + 1][j - 1][cur][k] %= M; // add, merge dp[i + 1][j][cur][k] += (j * 2LL - k) * dp[i][j][l][k]; dp[i + 1][j][cur][k] %= M; // add, merge one ending point dp[i + 1][j + 1][cur][k] += (j + 1LL - k) * dp[i][j][l][k]; dp[i + 1][j + 1][cur][k] %= M; // add, no merge if (k == 2) continue; dp[i + 1][j][cur][k + 1] += (2LL - k) * dp[i][j][l][k]; dp[i + 1][j][cur][k + 1] %= M; // add, fix, merge dp[i + 1][j + 1][cur][k + 1] = (2LL - k) * dp[i][j][l][k]; dp[i + 1][j + 1][cur][k + 1] %= M; // add, fix, no merge } } } } for (int i = 1; i <= d; i++) dp[n][1][i][2] += dp[n][1][i - 1][2], dp[n][1][i][2] %= M; printf("%lld", (dp[n][1][d][2] + (n == 1)) % M); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:11:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   11 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + n + 1);
      |     ^~~
skyscraper.cpp:11:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   11 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + n + 1);
      |                                                        ^~~~
skyscraper.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%lld %lld", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:11:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + n + 1);
      |                                  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...