# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41707 | 2018-02-21T02:15:27 Z | fallingstar | Skyscraper (JOI16_skyscraper) | C++14 | 89 ms | 16376 KB |
/** Problem: Skyscraper Source: JOI Open Contest 2016 Problem 3 Solution: Connected Component DP */ #include <cstdio> #include <algorithm> using namespace std; #define long long long const int N = 100 + 2; const int MOD = 1e9 + 7; const int L = 1000 + 2; void AddMod(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int MulMod(int a, int b) { return (long) a * b % MOD; } int n, lim, a[N], dp[N][N][L][3]; int main() { scanf("%d %d", &n, &lim); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); dp[0][0][0][0] = 1; for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) for (int k = 0; k <= lim; ++k) for (int l = 0; l <= 2; ++l) { int new_k = k + (a[i + 1] - a[i]) * (j * 2 - l); if (new_k > lim || !dp[i][j][k][l]) continue; // add new component AddMod(dp[i + 1][j + 1][new_k][l], MulMod(dp[i][j][k][l], j - 1 + 2 - l)); if (l < 2) AddMod(dp[i + 1][j + 1][new_k][l + 1], MulMod(dp[i][j][k][l], 2 - l)); // connect two component if (j >= 2) AddMod(dp[i + 1][j - 1][new_k][l], MulMod(dp[i][j][k][l], j - 1)); // to component's end if (j > 0) AddMod(dp[i + 1][j][new_k][l], MulMod(dp[i][j][k][l], j * 2 - l)); if (j > 0 && l < 2) AddMod(dp[i + 1][j][new_k][l + 1], MulMod(dp[i][j][k][l], 2 - l)); } int res = 0; for (int k = 0; k <= lim; ++k) AddMod(res, dp[n][1][k][2]); printf("%d", n > 1 ? res : 1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 1 ms | 428 KB | Output is correct |
4 | Correct | 2 ms | 536 KB | Output is correct |
5 | Correct | 2 ms | 668 KB | Output is correct |
6 | Correct | 2 ms | 852 KB | Output is correct |
7 | Correct | 1 ms | 852 KB | Output is correct |
8 | Correct | 1 ms | 852 KB | Output is correct |
9 | Correct | 2 ms | 852 KB | Output is correct |
10 | Correct | 1 ms | 852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 940 KB | Output is correct |
2 | Correct | 2 ms | 940 KB | Output is correct |
3 | Correct | 2 ms | 944 KB | Output is correct |
4 | Correct | 2 ms | 944 KB | Output is correct |
5 | Correct | 2 ms | 944 KB | Output is correct |
6 | Correct | 2 ms | 944 KB | Output is correct |
7 | Correct | 1 ms | 944 KB | Output is correct |
8 | Correct | 2 ms | 944 KB | Output is correct |
9 | Correct | 2 ms | 944 KB | Output is correct |
10 | Correct | 2 ms | 944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 1 ms | 428 KB | Output is correct |
4 | Correct | 2 ms | 536 KB | Output is correct |
5 | Correct | 2 ms | 668 KB | Output is correct |
6 | Correct | 2 ms | 852 KB | Output is correct |
7 | Correct | 1 ms | 852 KB | Output is correct |
8 | Correct | 1 ms | 852 KB | Output is correct |
9 | Correct | 2 ms | 852 KB | Output is correct |
10 | Correct | 1 ms | 852 KB | Output is correct |
11 | Correct | 2 ms | 940 KB | Output is correct |
12 | Correct | 2 ms | 940 KB | Output is correct |
13 | Correct | 2 ms | 944 KB | Output is correct |
14 | Correct | 2 ms | 944 KB | Output is correct |
15 | Correct | 2 ms | 944 KB | Output is correct |
16 | Correct | 2 ms | 944 KB | Output is correct |
17 | Correct | 1 ms | 944 KB | Output is correct |
18 | Correct | 2 ms | 944 KB | Output is correct |
19 | Correct | 2 ms | 944 KB | Output is correct |
20 | Correct | 2 ms | 944 KB | Output is correct |
21 | Correct | 3 ms | 1620 KB | Output is correct |
22 | Correct | 89 ms | 16376 KB | Output is correct |
23 | Correct | 50 ms | 16376 KB | Output is correct |
24 | Correct | 55 ms | 16376 KB | Output is correct |
25 | Correct | 62 ms | 16376 KB | Output is correct |
26 | Correct | 46 ms | 16376 KB | Output is correct |
27 | Correct | 35 ms | 16376 KB | Output is correct |
28 | Correct | 49 ms | 16376 KB | Output is correct |
29 | Correct | 65 ms | 16376 KB | Output is correct |
30 | Correct | 56 ms | 16376 KB | Output is correct |