답안 #624270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624270 2022-08-07T15:49:06 Z Ronin13 Group Photo (JOI21_ho_t3) C++14
100 / 100
413 ms 165456 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int NMAX = 5005;
int pre[NMAX][NMAX];
int dp[NMAX][NMAX];
int DP[NMAX];
int dpb[NMAX];
int main(){
    int n; cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    int pos[n + 1];
    for(int i = 1; i <= n; i++) pos[a[i]] = i;
    for(int i = 1; i <= n; i++){
        dp[i][0] = 0;
        for(int j = 1; j <= n; j++){
            dp[i][j] = dp[i][j - 1];
            if(pos[i] > pos[j]) dp[i][j]++;
        }
    }
    for(int i = n; i >= 1; i--){
        pre[i][i] = i - 1 - dp[i][i];
        for(int j = i + 1; j <= n; j++){
            pre[i][j] = pre[i][j - 1] + dp[j][j] - dp[j][i - 1] + i - 1 -  dp[j][i - 1] ;
        }
    }
    DP[0] = 0;
    for(int i= 1; i <= n; i++){
        DP[i] = 1e9;
        int mni;
        for(int j = 0; j < i; j++){
            DP[i] = min(DP[i], pre[j + 1][i] + DP[j]);
        }

    }
    cout << DP[n];
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:13: warning: unused variable 'mni' [-Wunused-variable]
   39 |         int mni;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 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 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 584 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 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 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 584 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 1 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 1 ms 2132 KB Output is correct
25 Correct 2 ms 2132 KB Output is correct
26 Correct 1 ms 2132 KB Output is correct
27 Correct 1 ms 2096 KB Output is correct
28 Correct 1 ms 2132 KB Output is correct
29 Correct 2 ms 2132 KB Output is correct
30 Correct 1 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 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 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 584 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 1 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 1 ms 2132 KB Output is correct
25 Correct 2 ms 2132 KB Output is correct
26 Correct 1 ms 2132 KB Output is correct
27 Correct 1 ms 2096 KB Output is correct
28 Correct 1 ms 2132 KB Output is correct
29 Correct 2 ms 2132 KB Output is correct
30 Correct 1 ms 2132 KB Output is correct
31 Correct 10 ms 10452 KB Output is correct
32 Correct 9 ms 10452 KB Output is correct
33 Correct 9 ms 10424 KB Output is correct
34 Correct 8 ms 10420 KB Output is correct
35 Correct 9 ms 10452 KB Output is correct
36 Correct 8 ms 10452 KB Output is correct
37 Correct 8 ms 10452 KB Output is correct
38 Correct 8 ms 10452 KB Output is correct
39 Correct 9 ms 10472 KB Output is correct
40 Correct 11 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 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 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 584 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 1 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 1 ms 2132 KB Output is correct
25 Correct 2 ms 2132 KB Output is correct
26 Correct 1 ms 2132 KB Output is correct
27 Correct 1 ms 2096 KB Output is correct
28 Correct 1 ms 2132 KB Output is correct
29 Correct 2 ms 2132 KB Output is correct
30 Correct 1 ms 2132 KB Output is correct
31 Correct 10 ms 10452 KB Output is correct
32 Correct 9 ms 10452 KB Output is correct
33 Correct 9 ms 10424 KB Output is correct
34 Correct 8 ms 10420 KB Output is correct
35 Correct 9 ms 10452 KB Output is correct
36 Correct 8 ms 10452 KB Output is correct
37 Correct 8 ms 10452 KB Output is correct
38 Correct 8 ms 10452 KB Output is correct
39 Correct 9 ms 10472 KB Output is correct
40 Correct 11 ms 10468 KB Output is correct
41 Correct 406 ms 165120 KB Output is correct
42 Correct 413 ms 165212 KB Output is correct
43 Correct 402 ms 165196 KB Output is correct
44 Correct 407 ms 165220 KB Output is correct
45 Correct 392 ms 165196 KB Output is correct
46 Correct 374 ms 165240 KB Output is correct
47 Correct 407 ms 165284 KB Output is correct
48 Correct 402 ms 165196 KB Output is correct
49 Correct 409 ms 165456 KB Output is correct
50 Correct 405 ms 165236 KB Output is correct
51 Correct 393 ms 165168 KB Output is correct
52 Correct 405 ms 165248 KB Output is correct
53 Correct 413 ms 165268 KB Output is correct
54 Correct 396 ms 165280 KB Output is correct
55 Correct 391 ms 165364 KB Output is correct