Submission #751019

#TimeUsernameProblemLanguageResultExecution timeMemory
751019Sami_MassahSkyscraper (JOI16_skyscraper)C++17
100 / 100
127 ms5816 KiB
#include <bits/stdc++.h> using namespace std; const long long maxn = 100 + 12, maxk = 3000, inf = 1001, 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]; // a[i] = i * 2 + 1; } if(n == 1){ cout << 1 << endl; return 0; } 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 = 0; 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:36:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   36 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
      |                                              ~~^~~
skyscraper.cpp:40:52: 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 - 1] * (2 - (m - 1));
      |                                                  ~~^~~
skyscraper.cpp:43:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   43 |                     dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
      |                                              ~~^~~
skyscraper.cpp:46:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   46 |                         dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
      |                                                  ~~^~~
skyscraper.cpp:48:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   48 |                     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...