# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
628832 |
2022-08-13T18:00:06 Z |
groshi |
Group Photo (JOI21_ho_t3) |
C++17 |
|
502 ms |
117948 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;
int mniejsze[6000];///ile mniejszych na lewo od wartosci + prefiksowe na tym
int dp[6000];
int gdzie[6000];
int zmiana[6000][6000];///ile na przedziale + prefiksowe
int t[6000];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t[i];
gdzie[t[i]]=i;
}
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
if(t[j]<t[i])
mniejsze[t[i]]++;
for(int i=1;i<=n;i++)
mniejsze[i]+=mniejsze[i-1];
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
zmiana[t[i]][t[j]]++;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
zmiana[t[i]][j]+=zmiana[t[i]][j-1];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
zmiana[i][j]+=zmiana[i-1][j];
for(int i=1;i<=n;i++)
dp[i]=1e9;
dp[0]=0;
for(int i=1;i<=n;i++)
for(int j=i;j>=1;j--)
dp[i]=min(dp[i],dp[j-1]+zmiana[i][n]-zmiana[j-1][n]-(zmiana[i][i]-zmiana[j-1][i])-(zmiana[i][j-1]-zmiana[j-1][j-1])+mniejsze[i]-mniejsze[j-1]);
cout<<dp[n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1220 KB |
Output is correct |
22 |
Correct |
1 ms |
1220 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
1236 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1236 KB |
Output is correct |
27 |
Correct |
2 ms |
1236 KB |
Output is correct |
28 |
Correct |
1 ms |
1236 KB |
Output is correct |
29 |
Correct |
2 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1220 KB |
Output is correct |
22 |
Correct |
1 ms |
1220 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
1236 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1236 KB |
Output is correct |
27 |
Correct |
2 ms |
1236 KB |
Output is correct |
28 |
Correct |
1 ms |
1236 KB |
Output is correct |
29 |
Correct |
2 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1220 KB |
Output is correct |
31 |
Correct |
9 ms |
6028 KB |
Output is correct |
32 |
Correct |
8 ms |
5956 KB |
Output is correct |
33 |
Correct |
8 ms |
5972 KB |
Output is correct |
34 |
Correct |
8 ms |
5972 KB |
Output is correct |
35 |
Correct |
8 ms |
6100 KB |
Output is correct |
36 |
Correct |
9 ms |
6100 KB |
Output is correct |
37 |
Correct |
7 ms |
6100 KB |
Output is correct |
38 |
Correct |
9 ms |
6080 KB |
Output is correct |
39 |
Correct |
7 ms |
6100 KB |
Output is correct |
40 |
Correct |
7 ms |
6088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1220 KB |
Output is correct |
22 |
Correct |
1 ms |
1220 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
1236 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
2 ms |
1236 KB |
Output is correct |
27 |
Correct |
2 ms |
1236 KB |
Output is correct |
28 |
Correct |
1 ms |
1236 KB |
Output is correct |
29 |
Correct |
2 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1220 KB |
Output is correct |
31 |
Correct |
9 ms |
6028 KB |
Output is correct |
32 |
Correct |
8 ms |
5956 KB |
Output is correct |
33 |
Correct |
8 ms |
5972 KB |
Output is correct |
34 |
Correct |
8 ms |
5972 KB |
Output is correct |
35 |
Correct |
8 ms |
6100 KB |
Output is correct |
36 |
Correct |
9 ms |
6100 KB |
Output is correct |
37 |
Correct |
7 ms |
6100 KB |
Output is correct |
38 |
Correct |
9 ms |
6080 KB |
Output is correct |
39 |
Correct |
7 ms |
6100 KB |
Output is correct |
40 |
Correct |
7 ms |
6088 KB |
Output is correct |
41 |
Correct |
502 ms |
117768 KB |
Output is correct |
42 |
Correct |
488 ms |
117800 KB |
Output is correct |
43 |
Correct |
460 ms |
117820 KB |
Output is correct |
44 |
Correct |
466 ms |
117752 KB |
Output is correct |
45 |
Correct |
479 ms |
117784 KB |
Output is correct |
46 |
Correct |
473 ms |
117840 KB |
Output is correct |
47 |
Correct |
483 ms |
117944 KB |
Output is correct |
48 |
Correct |
454 ms |
117944 KB |
Output is correct |
49 |
Correct |
471 ms |
117828 KB |
Output is correct |
50 |
Correct |
461 ms |
117840 KB |
Output is correct |
51 |
Correct |
454 ms |
117824 KB |
Output is correct |
52 |
Correct |
452 ms |
117948 KB |
Output is correct |
53 |
Correct |
469 ms |
117816 KB |
Output is correct |
54 |
Correct |
456 ms |
117836 KB |
Output is correct |
55 |
Correct |
438 ms |
117836 KB |
Output is correct |