# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034982 |
2024-07-26T02:07:55 Z |
juicy |
Group Photo (JOI21_ho_t3) |
C++17 |
|
316 ms |
134480 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e3 + 5;
int n;
int h[N], pos[N], f[N][N], g[N][N], dp[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
pos[h[i]] = i;
}
for (int i = 1; i <= n; ++i) {
for (int j = n; j >= i; --j) {
f[i][j] = f[i][j + 1] + (pos[j] < pos[i]);
}
for (int j = i; j > 0; --j) {
g[j][i] = g[j + 1][i] + (pos[j] < pos[i]);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = i - 2; j >= 1; --j) {
f[j][i] += f[j + 1][i];
}
for (int j = i + 2; j <= n; ++j) {
g[i][j] += g[i][j - 1];
}
}
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < i; ++j) {
dp[i] = min(dp[i], dp[j] + f[j + 1][i + 1] + g[j + 1][i]);
}
}
cout << dp[n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
2140 KB |
Output is correct |
22 |
Correct |
1 ms |
2140 KB |
Output is correct |
23 |
Correct |
1 ms |
2140 KB |
Output is correct |
24 |
Correct |
1 ms |
2140 KB |
Output is correct |
25 |
Correct |
1 ms |
2140 KB |
Output is correct |
26 |
Correct |
1 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
2140 KB |
Output is correct |
28 |
Correct |
1 ms |
2140 KB |
Output is correct |
29 |
Correct |
1 ms |
2140 KB |
Output is correct |
30 |
Correct |
1 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
2140 KB |
Output is correct |
22 |
Correct |
1 ms |
2140 KB |
Output is correct |
23 |
Correct |
1 ms |
2140 KB |
Output is correct |
24 |
Correct |
1 ms |
2140 KB |
Output is correct |
25 |
Correct |
1 ms |
2140 KB |
Output is correct |
26 |
Correct |
1 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
2140 KB |
Output is correct |
28 |
Correct |
1 ms |
2140 KB |
Output is correct |
29 |
Correct |
1 ms |
2140 KB |
Output is correct |
30 |
Correct |
1 ms |
2136 KB |
Output is correct |
31 |
Correct |
9 ms |
9308 KB |
Output is correct |
32 |
Correct |
8 ms |
9308 KB |
Output is correct |
33 |
Correct |
8 ms |
9308 KB |
Output is correct |
34 |
Correct |
8 ms |
9192 KB |
Output is correct |
35 |
Correct |
8 ms |
9308 KB |
Output is correct |
36 |
Correct |
7 ms |
9420 KB |
Output is correct |
37 |
Correct |
10 ms |
9308 KB |
Output is correct |
38 |
Correct |
8 ms |
9428 KB |
Output is correct |
39 |
Correct |
7 ms |
9304 KB |
Output is correct |
40 |
Correct |
7 ms |
9304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
2140 KB |
Output is correct |
22 |
Correct |
1 ms |
2140 KB |
Output is correct |
23 |
Correct |
1 ms |
2140 KB |
Output is correct |
24 |
Correct |
1 ms |
2140 KB |
Output is correct |
25 |
Correct |
1 ms |
2140 KB |
Output is correct |
26 |
Correct |
1 ms |
2140 KB |
Output is correct |
27 |
Correct |
1 ms |
2140 KB |
Output is correct |
28 |
Correct |
1 ms |
2140 KB |
Output is correct |
29 |
Correct |
1 ms |
2140 KB |
Output is correct |
30 |
Correct |
1 ms |
2136 KB |
Output is correct |
31 |
Correct |
9 ms |
9308 KB |
Output is correct |
32 |
Correct |
8 ms |
9308 KB |
Output is correct |
33 |
Correct |
8 ms |
9308 KB |
Output is correct |
34 |
Correct |
8 ms |
9192 KB |
Output is correct |
35 |
Correct |
8 ms |
9308 KB |
Output is correct |
36 |
Correct |
7 ms |
9420 KB |
Output is correct |
37 |
Correct |
10 ms |
9308 KB |
Output is correct |
38 |
Correct |
8 ms |
9428 KB |
Output is correct |
39 |
Correct |
7 ms |
9304 KB |
Output is correct |
40 |
Correct |
7 ms |
9304 KB |
Output is correct |
41 |
Correct |
302 ms |
134160 KB |
Output is correct |
42 |
Correct |
298 ms |
134228 KB |
Output is correct |
43 |
Correct |
316 ms |
134224 KB |
Output is correct |
44 |
Correct |
303 ms |
134224 KB |
Output is correct |
45 |
Correct |
302 ms |
134240 KB |
Output is correct |
46 |
Correct |
305 ms |
134296 KB |
Output is correct |
47 |
Correct |
307 ms |
134408 KB |
Output is correct |
48 |
Correct |
302 ms |
134480 KB |
Output is correct |
49 |
Correct |
303 ms |
134268 KB |
Output is correct |
50 |
Correct |
310 ms |
134432 KB |
Output is correct |
51 |
Correct |
296 ms |
134476 KB |
Output is correct |
52 |
Correct |
297 ms |
134224 KB |
Output is correct |
53 |
Correct |
304 ms |
134420 KB |
Output is correct |
54 |
Correct |
286 ms |
134340 KB |
Output is correct |
55 |
Correct |
286 ms |
134324 KB |
Output is correct |