Submission #390640

# Submission time Handle Problem Language Result Execution time Memory
390640 2021-04-16T12:47:37 Z wildturtle Group Photo (JOI21_ho_t3) C++14
100 / 100
740 ms 313412 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l;
ll A[5003],B[5003],C[5003][5003],D[5003][5003],dp[5003];
int main() {
    cin>>n;
    for(ll i=1;i<=n;i++) {
        cin>>A[i];
        B[A[i]]=i;
        dp[i]=1e18;
    }
    for(ll i=1;i<=n;i++) {
        for(ll j=n;j>=1;j--) {
            C[i][j]=C[i][j+1];
            if(B[j]<B[i]) C[i][j]++;
        }
    }
    for(ll i=1;i<=n;i++) {
        for(ll j=i;j<=n;j++) {
            D[i][j]=C[j][i]+D[i][j-1]-((j-1)-i+1-(C[j][i]-C[j][j+1]));
        }
    }
    for(ll i=1;i<=n;i++) {
        for(ll j=i-1;j>=0;j--) {
            dp[i]=min(dp[i],dp[j]+D[j+1][i]);
        }
    }
    cout<<dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 2356 KB Output is correct
22 Correct 2 ms 2380 KB Output is correct
23 Correct 2 ms 2380 KB Output is correct
24 Correct 2 ms 2348 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 2 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 2 ms 2380 KB Output is correct
29 Correct 2 ms 2380 KB Output is correct
30 Correct 3 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 2356 KB Output is correct
22 Correct 2 ms 2380 KB Output is correct
23 Correct 2 ms 2380 KB Output is correct
24 Correct 2 ms 2348 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 2 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 2 ms 2380 KB Output is correct
29 Correct 2 ms 2380 KB Output is correct
30 Correct 3 ms 2380 KB Output is correct
31 Correct 17 ms 14220 KB Output is correct
32 Correct 14 ms 14252 KB Output is correct
33 Correct 14 ms 14312 KB Output is correct
34 Correct 14 ms 14284 KB Output is correct
35 Correct 14 ms 14284 KB Output is correct
36 Correct 15 ms 14372 KB Output is correct
37 Correct 14 ms 14288 KB Output is correct
38 Correct 14 ms 14284 KB Output is correct
39 Correct 15 ms 14284 KB Output is correct
40 Correct 15 ms 14256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 304 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 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 2356 KB Output is correct
22 Correct 2 ms 2380 KB Output is correct
23 Correct 2 ms 2380 KB Output is correct
24 Correct 2 ms 2348 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 2 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 2 ms 2380 KB Output is correct
29 Correct 2 ms 2380 KB Output is correct
30 Correct 3 ms 2380 KB Output is correct
31 Correct 17 ms 14220 KB Output is correct
32 Correct 14 ms 14252 KB Output is correct
33 Correct 14 ms 14312 KB Output is correct
34 Correct 14 ms 14284 KB Output is correct
35 Correct 14 ms 14284 KB Output is correct
36 Correct 15 ms 14372 KB Output is correct
37 Correct 14 ms 14288 KB Output is correct
38 Correct 14 ms 14284 KB Output is correct
39 Correct 15 ms 14284 KB Output is correct
40 Correct 15 ms 14256 KB Output is correct
41 Correct 740 ms 312900 KB Output is correct
42 Correct 728 ms 313048 KB Output is correct
43 Correct 740 ms 313184 KB Output is correct
44 Correct 734 ms 313132 KB Output is correct
45 Correct 729 ms 313308 KB Output is correct
46 Correct 717 ms 313180 KB Output is correct
47 Correct 720 ms 313196 KB Output is correct
48 Correct 737 ms 313284 KB Output is correct
49 Correct 717 ms 313184 KB Output is correct
50 Correct 717 ms 313192 KB Output is correct
51 Correct 729 ms 313200 KB Output is correct
52 Correct 739 ms 313220 KB Output is correct
53 Correct 723 ms 313152 KB Output is correct
54 Correct 723 ms 313412 KB Output is correct
55 Correct 734 ms 313156 KB Output is correct