# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
959083 |
2024-04-07T13:15:33 Z |
anton |
Group Photo (JOI21_ho_t3) |
C++17 |
|
337 ms |
196452 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 5001;
int n;
int dp[MAX_N];
int vals[MAX_N];
int pos[MAX_N];
int oc_under_pref[MAX_N][MAX_N];
void precalc(){
for(int i = 0; i<=n; i++){
vector<int> oc(n, 0);
for(int j = 0; j<i; j++){
oc[vals[j]]++;
}
int cur = 0;
for(int j=0; j<=n; j++){
oc_under_pref[i][j] = cur;
if(j<n){
cur += oc[j];
}
}
}
}
int find_dp(){
dp[0] = 0;
for(int i = 0; i<n; i++){
int cur_c= 0;
for(int j = i; j<n; j++){
//cout<<"j "<<j<<" "<<pos[j]<<" "<<oc_under_pref[pos[j]][j]<<endl;
cur_c += pos[j]-oc_under_pref[pos[j]][i];
cur_c-= (oc_under_pref[n][j]-oc_under_pref[n][i]-oc_under_pref[pos[j]][j]+oc_under_pref[pos[j]][i]);
dp[j+1] =min(dp[j+1], dp[i]+cur_c);
}
}
return dp[n];
}
signed main(){
cin>>n;
for(int i = 0; i<n; i++){
cin>>vals[i];
vals[i]--;
pos[vals[i]] = i;
}
for(int i = 0; i<=n; i++){
dp[i] = 1e18;
}
precalc();
cout<<find_dp()<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2488 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2488 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8536 KB |
Output is correct |
28 |
Correct |
2 ms |
8792 KB |
Output is correct |
29 |
Correct |
1 ms |
8632 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2488 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8536 KB |
Output is correct |
28 |
Correct |
2 ms |
8792 KB |
Output is correct |
29 |
Correct |
1 ms |
8632 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
10 ms |
33116 KB |
Output is correct |
32 |
Correct |
7 ms |
33116 KB |
Output is correct |
33 |
Correct |
7 ms |
33332 KB |
Output is correct |
34 |
Correct |
7 ms |
33116 KB |
Output is correct |
35 |
Correct |
8 ms |
33112 KB |
Output is correct |
36 |
Correct |
7 ms |
33368 KB |
Output is correct |
37 |
Correct |
6 ms |
33116 KB |
Output is correct |
38 |
Correct |
7 ms |
33116 KB |
Output is correct |
39 |
Correct |
7 ms |
33116 KB |
Output is correct |
40 |
Correct |
8 ms |
33300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2400 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2488 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8536 KB |
Output is correct |
28 |
Correct |
2 ms |
8792 KB |
Output is correct |
29 |
Correct |
1 ms |
8632 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
10 ms |
33116 KB |
Output is correct |
32 |
Correct |
7 ms |
33116 KB |
Output is correct |
33 |
Correct |
7 ms |
33332 KB |
Output is correct |
34 |
Correct |
7 ms |
33116 KB |
Output is correct |
35 |
Correct |
8 ms |
33112 KB |
Output is correct |
36 |
Correct |
7 ms |
33368 KB |
Output is correct |
37 |
Correct |
6 ms |
33116 KB |
Output is correct |
38 |
Correct |
7 ms |
33116 KB |
Output is correct |
39 |
Correct |
7 ms |
33116 KB |
Output is correct |
40 |
Correct |
8 ms |
33300 KB |
Output is correct |
41 |
Correct |
337 ms |
196248 KB |
Output is correct |
42 |
Correct |
281 ms |
196176 KB |
Output is correct |
43 |
Correct |
270 ms |
196452 KB |
Output is correct |
44 |
Correct |
271 ms |
196328 KB |
Output is correct |
45 |
Correct |
263 ms |
196428 KB |
Output is correct |
46 |
Correct |
261 ms |
196364 KB |
Output is correct |
47 |
Correct |
280 ms |
196368 KB |
Output is correct |
48 |
Correct |
271 ms |
196180 KB |
Output is correct |
49 |
Correct |
275 ms |
196364 KB |
Output is correct |
50 |
Correct |
274 ms |
196180 KB |
Output is correct |
51 |
Correct |
268 ms |
196360 KB |
Output is correct |
52 |
Correct |
281 ms |
196180 KB |
Output is correct |
53 |
Correct |
272 ms |
196360 KB |
Output is correct |
54 |
Correct |
274 ms |
196364 KB |
Output is correct |
55 |
Correct |
268 ms |
196364 KB |
Output is correct |