Submission #751010

#TimeUsernameProblemLanguageResultExecution timeMemory
751010Sami_MassahSkyscraper (JOI16_skyscraper)C++17
15 / 100
2 ms468 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 12, maxk = 1000, inf = 1000 + 1, mod = 1e9 + 7; long long n, mx, a[maxn], dp[2][maxn][maxk][3]; int main(){ cin >> n >> mx; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for(int i = n; i >= 1; i--) swap(a[i], a[i - 1]); a[n + 1] = inf; //cout << a[1] << ' ' << a[2] << endl; dp[0][0][0][0] = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) for(int c = 1; c <= mx; c++) for(int m = 0; m <= 2; m++){ int delta = (2 * j - m) * (a[i + 1] - a[i]); dp[i & 1][j][c][m] = 0; if(i == 2) dp[0][0][0][0] = 0; if(delta > c) continue; dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m); if(m > 0){ dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1)); } dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m); if(m > 0) dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m); dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j); dp[i & 1][j][c][m] %= mod; // cout << i << ' ' << j + 1 << ' ' << c- delta << ' ' << m <<' ' << dp[i][j + 1][c - delta][m] << endl << endl; } long long ans = 0; for(int c = 1; c <= mx; c++){ ans += dp[n & 1][1][c][2]; ans %= mod; } cout << ans << endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:28:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   28 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
      |                                              ~~^~~
skyscraper.cpp:32:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   32 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
      |                                                  ~~^~~
skyscraper.cpp:35:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
      |                                              ~~^~~
skyscraper.cpp:38:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   38 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
      |                                                  ~~^~~
skyscraper.cpp:40:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   40 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j);
      |                                              ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...