# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
372812 | 2021-03-01T20:39:46 Z | MiricaMatei | Skyscraper (JOI16_skyscraper) | C++14 | 106 ms | 2924 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const int MAXL = 1005; const int MOD = 1e9 + 7; int a[MAXN]; int dp[3][MAXN][MAXL][3]; int main() { //freopen("date.in", "r", stdin); //freopen("date.out", "w", stdout); int n, l; scanf("%d%d", &n, &l); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); dp[1][0][0][0] = 1; dp[1][0][0][1] = 2; dp[1][0][0][2] = 1; for (int i = 1; i < n; ++i) { int dif = a[i] - a[i + 1]; int pv = i & 1; int nx = (pv ^ 1); for (int j = 0; j <= i + 1; ++j) { for (int s = 0; s <= l; ++s) { for (int e = 0; e <= 2; ++e) { int ns = s + dif * (2 * j + 2 - e); if (ns > l) continue; if (j - 1 >= 0) dp[nx][j - 1][ns][e] = (dp[nx][j - 1][ns][e] + 1LL * j * dp[pv][j][s][e]) % MOD; dp[nx][j][ns][e] = (dp[nx][j][ns][e] + 1LL * (2 * j + 2 - e) * dp[pv][j][s][e]) % MOD; dp[nx][j + 1][ns][e] = (dp[nx][j + 1][ns][e] + 1LL * (j + 2 - e) * dp[pv][j][s][e]) % MOD; if (e + 1 <= 2) dp[nx][j][ns][e + 1] = (dp[nx][j][ns][e + 1] + 1LL * (2 - e) * dp[pv][j][s][e]) % MOD; if (e + 1 <= 2) dp[nx][j + 1][ns][e + 1] = (dp[nx][j + 1][ns][e + 1] + 1LL * (2 - e) * dp[pv][j][s][e]) % MOD; } } } memset(dp[pv], 0, sizeof(dp[pv])); } int ans = 0; for (int i = 0; i <= l; ++i) ans = (ans + dp[n & 1][0][i][2]) % MOD; printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 1516 KB | Output is correct |
3 | Correct | 2 ms | 2796 KB | Output is correct |
4 | Correct | 2 ms | 2796 KB | Output is correct |
5 | Correct | 3 ms | 2796 KB | Output is correct |
6 | Correct | 3 ms | 2796 KB | Output is correct |
7 | Correct | 2 ms | 2796 KB | Output is correct |
8 | Correct | 2 ms | 2796 KB | Output is correct |
9 | Correct | 3 ms | 2796 KB | Output is correct |
10 | Correct | 2 ms | 2796 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2796 KB | Output is correct |
2 | Correct | 3 ms | 2796 KB | Output is correct |
3 | Correct | 2 ms | 2796 KB | Output is correct |
4 | Correct | 3 ms | 2796 KB | Output is correct |
5 | Correct | 3 ms | 2796 KB | Output is correct |
6 | Correct | 3 ms | 2796 KB | Output is correct |
7 | Correct | 3 ms | 2796 KB | Output is correct |
8 | Correct | 2 ms | 2796 KB | Output is correct |
9 | Correct | 3 ms | 2816 KB | Output is correct |
10 | Correct | 3 ms | 2796 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 1516 KB | Output is correct |
3 | Correct | 2 ms | 2796 KB | Output is correct |
4 | Correct | 2 ms | 2796 KB | Output is correct |
5 | Correct | 3 ms | 2796 KB | Output is correct |
6 | Correct | 3 ms | 2796 KB | Output is correct |
7 | Correct | 2 ms | 2796 KB | Output is correct |
8 | Correct | 2 ms | 2796 KB | Output is correct |
9 | Correct | 3 ms | 2796 KB | Output is correct |
10 | Correct | 2 ms | 2796 KB | Output is correct |
11 | Correct | 2 ms | 2796 KB | Output is correct |
12 | Correct | 3 ms | 2796 KB | Output is correct |
13 | Correct | 2 ms | 2796 KB | Output is correct |
14 | Correct | 3 ms | 2796 KB | Output is correct |
15 | Correct | 3 ms | 2796 KB | Output is correct |
16 | Correct | 3 ms | 2796 KB | Output is correct |
17 | Correct | 3 ms | 2796 KB | Output is correct |
18 | Correct | 2 ms | 2796 KB | Output is correct |
19 | Correct | 3 ms | 2816 KB | Output is correct |
20 | Correct | 3 ms | 2796 KB | Output is correct |
21 | Correct | 4 ms | 2796 KB | Output is correct |
22 | Correct | 79 ms | 2796 KB | Output is correct |
23 | Correct | 97 ms | 2796 KB | Output is correct |
24 | Correct | 86 ms | 2924 KB | Output is correct |
25 | Correct | 106 ms | 2796 KB | Output is correct |
26 | Correct | 86 ms | 2796 KB | Output is correct |
27 | Correct | 36 ms | 2924 KB | Output is correct |
28 | Correct | 44 ms | 2796 KB | Output is correct |
29 | Correct | 79 ms | 2924 KB | Output is correct |
30 | Correct | 101 ms | 2924 KB | Output is correct |