Submission #442847

#TimeUsernameProblemLanguageResultExecution timeMemory
442847parsabahramiSkyscraper (JOI16_skyscraper)C++17
100 / 100
269 ms84748 KiB
/* I do it for the glory */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e2 + 10, MOD = 1e9 + 7; int dp[N][N][10 * N][3], A[N], n, L; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { scanf("%d%d", &n, &L); dp[0][0][0][0] = 1; if (n < 2) return !printf("1\n"); for (int i = 1; i <= n; i++) scanf("%d", &A[i]); sort(A + 1, A + n + 1); for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= L; k++) { for (int t = 0; t <= min(j, 2); t++) { int nk = k + (A[i] - A[i - 1]) * (2 * j - t); if (nk > L) continue; add(dp[i][j + 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j + 1 - t) % MOD); if (t < 2) add(dp[i][j + 1][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD); if (t < 2 && j) add(dp[i][j][nk][t + 1], dp[i - 1][j][k][t] * (2ll - t) % MOD); if (j > 1) add(dp[i][j - 1][nk][t], 1ll * dp[i - 1][j][k][t] * (j - 1) % MOD); if (j) add(dp[i][j][nk][t], dp[i - 1][j][k][t] * 1ll * (2 * j - t) % MOD); } } } } int ret = 0; for (int i = 0; i <= L; i++) add(ret, dp[n][1][i][2]); printf("%d\n", ret); return 0; }

Compilation message (stderr)

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