# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
388755 | 2021-04-12T20:16:45 Z | CaroLinda | Group Photo (JOI21_ho_t3) | C++14 | 84 ms | 528 KB |
#include <bits/stdc++.h> #define lp(i,a,b) for(int i =a ; i < b ; i++) #define ll long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define sz(x) (int)(x.size()) #define pii pair<int,int> #define mk make_pair #define mkt make_tuple #define tiii tuple<int,int,int> const int MAXN = 5010 ; using namespace std ; int N ; int H[MAXN] , pos[MAXN] , art_pos[MAXN] ; int maior_esq[MAXN] ; int dp[MAXN] ; int main() { scanf("%d", &N ) ; lp(i,1,N+1) { scanf("%d", &H[i] ) ; pos[H[i]] = i ; } vector<int> v = {1} ; for(int i = 2 ; i <= N ; i++ ) { int p = -1 ; for(int j = 0 ; j < sz(v) ; j++ ) if( pos[ v[j] ] > pos[i] ) { p = j ; break ; } if(p == -1) v.pb(i) , p = sz(v)-1 ; else v.insert( v.begin()+p , i ) ; for(int j = p+1 ; j < sz(v) ; j++ ) maior_esq[ v[j] ]++ ; for(int j = 0 ;j < sz(v) ; j++ ) art_pos[ v[j] ] = j ; dp[i]= N*N ; int cost = 0 ; for(int g = i ; g > 0 ; g-- ) { cost += i-1-art_pos[g]-maior_esq[g] ; dp[i]=min(dp[i] , dp[g-1]+cost) ; } } printf("%d\n" , dp[N] ) ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 292 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 292 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 292 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
31 | Correct | 3 ms | 332 KB | Output is correct |
32 | Correct | 3 ms | 332 KB | Output is correct |
33 | Correct | 3 ms | 332 KB | Output is correct |
34 | Correct | 3 ms | 332 KB | Output is correct |
35 | Correct | 3 ms | 332 KB | Output is correct |
36 | Correct | 3 ms | 204 KB | Output is correct |
37 | Correct | 3 ms | 332 KB | Output is correct |
38 | Correct | 3 ms | 332 KB | Output is correct |
39 | Correct | 3 ms | 332 KB | Output is correct |
40 | Correct | 3 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 1 ms | 292 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 1 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 1 ms | 204 KB | Output is correct |
24 | Correct | 1 ms | 204 KB | Output is correct |
25 | Correct | 1 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 204 KB | Output is correct |
27 | Correct | 1 ms | 204 KB | Output is correct |
28 | Correct | 1 ms | 204 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
31 | Correct | 3 ms | 332 KB | Output is correct |
32 | Correct | 3 ms | 332 KB | Output is correct |
33 | Correct | 3 ms | 332 KB | Output is correct |
34 | Correct | 3 ms | 332 KB | Output is correct |
35 | Correct | 3 ms | 332 KB | Output is correct |
36 | Correct | 3 ms | 204 KB | Output is correct |
37 | Correct | 3 ms | 332 KB | Output is correct |
38 | Correct | 3 ms | 332 KB | Output is correct |
39 | Correct | 3 ms | 332 KB | Output is correct |
40 | Correct | 3 ms | 332 KB | Output is correct |
41 | Correct | 82 ms | 396 KB | Output is correct |
42 | Correct | 83 ms | 528 KB | Output is correct |
43 | Correct | 82 ms | 332 KB | Output is correct |
44 | Correct | 82 ms | 396 KB | Output is correct |
45 | Correct | 83 ms | 404 KB | Output is correct |
46 | Correct | 83 ms | 500 KB | Output is correct |
47 | Correct | 83 ms | 332 KB | Output is correct |
48 | Correct | 84 ms | 492 KB | Output is correct |
49 | Correct | 83 ms | 368 KB | Output is correct |
50 | Correct | 83 ms | 332 KB | Output is correct |
51 | Correct | 82 ms | 388 KB | Output is correct |
52 | Correct | 83 ms | 400 KB | Output is correct |
53 | Correct | 79 ms | 332 KB | Output is correct |
54 | Correct | 82 ms | 424 KB | Output is correct |
55 | Correct | 84 ms | 396 KB | Output is correct |