# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
388516 | 2021-04-11T20:26:37 Z | luciocf | Group Photo (JOI21_ho_t3) | C++14 | 922 ms | 67552 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3+10; const int inf = 1e9+10; struct FenwickTree { int bit[maxn]; void upd(int x, int v) { for (; x < maxn; x += (x&-x)) bit[x] += v; } int soma(int x) { int ans = 0; for (; x > 0; x -= (x&-x)) ans += bit[x]; return ans; } int get(int l, int r) { if (l > r) return 0; return soma(r) - soma(l-1); } } BIT[2]; int a[maxn]; int val[maxn][maxn]; int dp[maxn]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); a[x] = i; } for (int l = 1; l <= n; l++) { memset(BIT[0].bit, 0, sizeof BIT[0].bit); memset(BIT[1].bit, 0, sizeof BIT[1].bit); for (int i = l; i <= n; i++) BIT[0].upd(a[i], 1); for (int r = l; r <= n; r++) { val[l][r] = val[l][r-1]; val[l][r] -= BIT[1].get(a[r]+1, n); val[l][r] += BIT[0].get(1, a[r]-1); BIT[1].upd(a[r], 1); } } for (int i = 1; i <= n; i++) { dp[i] = inf; for (int j = 1; j <= i; j++) dp[i] = min(dp[i], val[j][i] + dp[j-1]); } printf("%d\n", dp[n]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 460 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 460 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 2 ms | 1100 KB | Output is correct |
22 | Correct | 2 ms | 1228 KB | Output is correct |
23 | Correct | 3 ms | 1100 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 3 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1232 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 460 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 2 ms | 1100 KB | Output is correct |
22 | Correct | 2 ms | 1228 KB | Output is correct |
23 | Correct | 3 ms | 1100 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 3 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1232 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
31 | Correct | 22 ms | 4704 KB | Output is correct |
32 | Correct | 27 ms | 4716 KB | Output is correct |
33 | Correct | 27 ms | 4808 KB | Output is correct |
34 | Correct | 21 ms | 4812 KB | Output is correct |
35 | Correct | 21 ms | 4688 KB | Output is correct |
36 | Correct | 21 ms | 4744 KB | Output is correct |
37 | Correct | 22 ms | 4720 KB | Output is correct |
38 | Correct | 22 ms | 4712 KB | Output is correct |
39 | Correct | 22 ms | 4712 KB | Output is correct |
40 | Correct | 22 ms | 4772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 0 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 300 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 460 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 2 ms | 1100 KB | Output is correct |
22 | Correct | 2 ms | 1228 KB | Output is correct |
23 | Correct | 3 ms | 1100 KB | Output is correct |
24 | Correct | 2 ms | 1228 KB | Output is correct |
25 | Correct | 3 ms | 1228 KB | Output is correct |
26 | Correct | 2 ms | 1228 KB | Output is correct |
27 | Correct | 2 ms | 1228 KB | Output is correct |
28 | Correct | 2 ms | 1232 KB | Output is correct |
29 | Correct | 2 ms | 1228 KB | Output is correct |
30 | Correct | 2 ms | 1228 KB | Output is correct |
31 | Correct | 22 ms | 4704 KB | Output is correct |
32 | Correct | 27 ms | 4716 KB | Output is correct |
33 | Correct | 27 ms | 4808 KB | Output is correct |
34 | Correct | 21 ms | 4812 KB | Output is correct |
35 | Correct | 21 ms | 4688 KB | Output is correct |
36 | Correct | 21 ms | 4744 KB | Output is correct |
37 | Correct | 22 ms | 4720 KB | Output is correct |
38 | Correct | 22 ms | 4712 KB | Output is correct |
39 | Correct | 22 ms | 4712 KB | Output is correct |
40 | Correct | 22 ms | 4772 KB | Output is correct |
41 | Correct | 917 ms | 67224 KB | Output is correct |
42 | Correct | 890 ms | 67332 KB | Output is correct |
43 | Correct | 887 ms | 67368 KB | Output is correct |
44 | Correct | 886 ms | 67304 KB | Output is correct |
45 | Correct | 889 ms | 67332 KB | Output is correct |
46 | Correct | 901 ms | 67360 KB | Output is correct |
47 | Correct | 873 ms | 67552 KB | Output is correct |
48 | Correct | 892 ms | 67388 KB | Output is correct |
49 | Correct | 875 ms | 67364 KB | Output is correct |
50 | Correct | 870 ms | 67432 KB | Output is correct |
51 | Correct | 864 ms | 67340 KB | Output is correct |
52 | Correct | 922 ms | 67256 KB | Output is correct |
53 | Correct | 901 ms | 67380 KB | Output is correct |
54 | Correct | 917 ms | 67364 KB | Output is correct |
55 | Correct | 876 ms | 67332 KB | Output is correct |