# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752945 | 2023-06-04T10:26:08 Z | IvanJ | Group Photo (JOI21_ho_t3) | C++17 | 587 ms | 160816 KB |
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define all(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 5e3 + 5; int n, ans = 0; int h[maxn]; int dp[maxn]; int solve(int N) { if(N < 2) return 0; if(dp[N] != -1) return dp[N]; vector<int> v; for(int i = 0;i < n;i++) if(h[i] <= N) v.pb(h[i]); vector<int> pos(N + 1, 0); for(int i = 0;i < N;i++) pos[v[i]] = i; int ret = 1e9; int cost = 0; vector<int> fwt(N + 1, 0); for(int i = N;i >= 1;i--) { cost += i - pos[i] - 1; { for(int x = N;x > 0;x -= (x & -x)) cost += fwt[x]; for(int x = pos[i] + 1;x > 0;x -= (x & -x)) cost -= fwt[x]; for(int x = pos[i] + 1;x <= N;x += (x & -x)) fwt[x]++; } //cout << i << " " << cost << "\n"; //cout << N << " " << i << " " << solve(i - 1) << " " << cost << "\n"; ret = min(ret, solve(i - 1) + cost); } return dp[N] = ret; } int main() { scanf("%d", &n); for(int i = 0;i < n;i++) scanf("%d", h + i); memset(dp, -1, sizeof dp); ans = solve(n); printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 300 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 304 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 300 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 304 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 2 ms | 596 KB | Output is correct |
22 | Correct | 2 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 596 KB | Output is correct |
24 | Correct | 2 ms | 564 KB | Output is correct |
25 | Correct | 2 ms | 560 KB | Output is correct |
26 | Correct | 2 ms | 564 KB | Output is correct |
27 | Correct | 2 ms | 596 KB | Output is correct |
28 | Correct | 2 ms | 596 KB | Output is correct |
29 | Correct | 2 ms | 596 KB | Output is correct |
30 | Correct | 2 ms | 596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 300 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 304 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 2 ms | 596 KB | Output is correct |
22 | Correct | 2 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 596 KB | Output is correct |
24 | Correct | 2 ms | 564 KB | Output is correct |
25 | Correct | 2 ms | 560 KB | Output is correct |
26 | Correct | 2 ms | 564 KB | Output is correct |
27 | Correct | 2 ms | 596 KB | Output is correct |
28 | Correct | 2 ms | 596 KB | Output is correct |
29 | Correct | 2 ms | 596 KB | Output is correct |
30 | Correct | 2 ms | 596 KB | Output is correct |
31 | Correct | 15 ms | 4808 KB | Output is correct |
32 | Correct | 16 ms | 4784 KB | Output is correct |
33 | Correct | 15 ms | 4824 KB | Output is correct |
34 | Correct | 13 ms | 4836 KB | Output is correct |
35 | Correct | 14 ms | 4836 KB | Output is correct |
36 | Correct | 14 ms | 4724 KB | Output is correct |
37 | Correct | 14 ms | 4836 KB | Output is correct |
38 | Correct | 15 ms | 4820 KB | Output is correct |
39 | Correct | 15 ms | 4832 KB | Output is correct |
40 | Correct | 13 ms | 4836 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Correct | 1 ms | 300 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 300 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 304 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 2 ms | 596 KB | Output is correct |
22 | Correct | 2 ms | 596 KB | Output is correct |
23 | Correct | 1 ms | 596 KB | Output is correct |
24 | Correct | 2 ms | 564 KB | Output is correct |
25 | Correct | 2 ms | 560 KB | Output is correct |
26 | Correct | 2 ms | 564 KB | Output is correct |
27 | Correct | 2 ms | 596 KB | Output is correct |
28 | Correct | 2 ms | 596 KB | Output is correct |
29 | Correct | 2 ms | 596 KB | Output is correct |
30 | Correct | 2 ms | 596 KB | Output is correct |
31 | Correct | 15 ms | 4808 KB | Output is correct |
32 | Correct | 16 ms | 4784 KB | Output is correct |
33 | Correct | 15 ms | 4824 KB | Output is correct |
34 | Correct | 13 ms | 4836 KB | Output is correct |
35 | Correct | 14 ms | 4836 KB | Output is correct |
36 | Correct | 14 ms | 4724 KB | Output is correct |
37 | Correct | 14 ms | 4836 KB | Output is correct |
38 | Correct | 15 ms | 4820 KB | Output is correct |
39 | Correct | 15 ms | 4832 KB | Output is correct |
40 | Correct | 13 ms | 4836 KB | Output is correct |
41 | Correct | 557 ms | 160444 KB | Output is correct |
42 | Correct | 530 ms | 160604 KB | Output is correct |
43 | Correct | 587 ms | 160664 KB | Output is correct |
44 | Correct | 556 ms | 160656 KB | Output is correct |
45 | Correct | 544 ms | 160660 KB | Output is correct |
46 | Correct | 575 ms | 160696 KB | Output is correct |
47 | Correct | 553 ms | 160588 KB | Output is correct |
48 | Correct | 528 ms | 160692 KB | Output is correct |
49 | Correct | 523 ms | 160692 KB | Output is correct |
50 | Correct | 538 ms | 160692 KB | Output is correct |
51 | Correct | 545 ms | 160688 KB | Output is correct |
52 | Correct | 538 ms | 160716 KB | Output is correct |
53 | Correct | 550 ms | 160688 KB | Output is correct |
54 | Correct | 576 ms | 160816 KB | Output is correct |
55 | Correct | 531 ms | 160716 KB | Output is correct |