답안 #634787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634787 2022-08-25T03:42:42 Z mdn2002 Group Photo (JOI21_ho_t3) C++14
100 / 100
901 ms 393032 KB
#include<bits/stdc++.h>
using namespace std;
long long n , a [5003] , bs [5003][5003] , wr [5003] , dp [5003][5003];
int f ( int x , int y )
{
    if ( x == n + 1 ) return 0;
    if ( dp [x][y] != -1 ) return dp [x][y];
    int ans = 1e9 , pos = x , posx = wr [y] + bs [y][ x - 1 ] , howmany = ( bs [y][ y - 1 ] - bs [y][ x - 1 ] );
    if ( x != y ) ans = min ( ans , f ( y , y ) );
    if ( y != n + 1 ) ans = min ( ans , f ( x , y + 1 ) + posx - pos - howmany );
    return dp [x][y] = ans;
}
int main ()
{
    memset ( dp , -1 , sizeof dp );
    cin >> n;
    for ( int i = 1 ; i <= n ; i ++ )
    {
        cin >> a [i];
        wr [ a [i] ] = i;
    }
    for ( int i = 1 ; i <= n ; i ++ )
    {
        for ( int j = i ; j <= n ; j ++ ) bs [ a [i] ][ a [j] ] ++;
        for ( int j = 1 ; j <= n ; j ++ ) bs [ a [i] ][j] += bs [ a [i] ][ j - 1 ];
    }
    cout << f ( 1 , 1 );
}
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 196172 KB Output is correct
2 Correct 73 ms 196248 KB Output is correct
3 Correct 72 ms 196132 KB Output is correct
4 Correct 79 ms 196204 KB Output is correct
5 Correct 72 ms 196252 KB Output is correct
6 Correct 75 ms 196220 KB Output is correct
7 Correct 74 ms 196248 KB Output is correct
8 Correct 85 ms 196228 KB Output is correct
9 Correct 71 ms 196172 KB Output is correct
10 Correct 72 ms 196216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 196172 KB Output is correct
2 Correct 73 ms 196248 KB Output is correct
3 Correct 72 ms 196132 KB Output is correct
4 Correct 79 ms 196204 KB Output is correct
5 Correct 72 ms 196252 KB Output is correct
6 Correct 75 ms 196220 KB Output is correct
7 Correct 74 ms 196248 KB Output is correct
8 Correct 85 ms 196228 KB Output is correct
9 Correct 71 ms 196172 KB Output is correct
10 Correct 72 ms 196216 KB Output is correct
11 Correct 73 ms 196276 KB Output is correct
12 Correct 71 ms 196252 KB Output is correct
13 Correct 84 ms 196288 KB Output is correct
14 Correct 75 ms 196240 KB Output is correct
15 Correct 73 ms 196300 KB Output is correct
16 Correct 76 ms 196224 KB Output is correct
17 Correct 79 ms 196304 KB Output is correct
18 Correct 74 ms 196212 KB Output is correct
19 Correct 72 ms 196212 KB Output is correct
20 Correct 75 ms 196300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 196172 KB Output is correct
2 Correct 73 ms 196248 KB Output is correct
3 Correct 72 ms 196132 KB Output is correct
4 Correct 79 ms 196204 KB Output is correct
5 Correct 72 ms 196252 KB Output is correct
6 Correct 75 ms 196220 KB Output is correct
7 Correct 74 ms 196248 KB Output is correct
8 Correct 85 ms 196228 KB Output is correct
9 Correct 71 ms 196172 KB Output is correct
10 Correct 72 ms 196216 KB Output is correct
11 Correct 73 ms 196276 KB Output is correct
12 Correct 71 ms 196252 KB Output is correct
13 Correct 84 ms 196288 KB Output is correct
14 Correct 75 ms 196240 KB Output is correct
15 Correct 73 ms 196300 KB Output is correct
16 Correct 76 ms 196224 KB Output is correct
17 Correct 79 ms 196304 KB Output is correct
18 Correct 74 ms 196212 KB Output is correct
19 Correct 72 ms 196212 KB Output is correct
20 Correct 75 ms 196300 KB Output is correct
21 Correct 76 ms 197384 KB Output is correct
22 Correct 73 ms 197344 KB Output is correct
23 Correct 76 ms 197372 KB Output is correct
24 Correct 74 ms 197396 KB Output is correct
25 Correct 88 ms 197336 KB Output is correct
26 Correct 73 ms 197288 KB Output is correct
27 Correct 73 ms 197316 KB Output is correct
28 Correct 73 ms 197324 KB Output is correct
29 Correct 73 ms 197284 KB Output is correct
30 Correct 76 ms 197372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 196172 KB Output is correct
2 Correct 73 ms 196248 KB Output is correct
3 Correct 72 ms 196132 KB Output is correct
4 Correct 79 ms 196204 KB Output is correct
5 Correct 72 ms 196252 KB Output is correct
6 Correct 75 ms 196220 KB Output is correct
7 Correct 74 ms 196248 KB Output is correct
8 Correct 85 ms 196228 KB Output is correct
9 Correct 71 ms 196172 KB Output is correct
10 Correct 72 ms 196216 KB Output is correct
11 Correct 73 ms 196276 KB Output is correct
12 Correct 71 ms 196252 KB Output is correct
13 Correct 84 ms 196288 KB Output is correct
14 Correct 75 ms 196240 KB Output is correct
15 Correct 73 ms 196300 KB Output is correct
16 Correct 76 ms 196224 KB Output is correct
17 Correct 79 ms 196304 KB Output is correct
18 Correct 74 ms 196212 KB Output is correct
19 Correct 72 ms 196212 KB Output is correct
20 Correct 75 ms 196300 KB Output is correct
21 Correct 76 ms 197384 KB Output is correct
22 Correct 73 ms 197344 KB Output is correct
23 Correct 76 ms 197372 KB Output is correct
24 Correct 74 ms 197396 KB Output is correct
25 Correct 88 ms 197336 KB Output is correct
26 Correct 73 ms 197288 KB Output is correct
27 Correct 73 ms 197316 KB Output is correct
28 Correct 73 ms 197324 KB Output is correct
29 Correct 73 ms 197284 KB Output is correct
30 Correct 76 ms 197372 KB Output is correct
31 Correct 96 ms 204576 KB Output is correct
32 Correct 96 ms 204620 KB Output is correct
33 Correct 86 ms 204588 KB Output is correct
34 Correct 86 ms 204540 KB Output is correct
35 Correct 88 ms 204592 KB Output is correct
36 Correct 84 ms 204588 KB Output is correct
37 Correct 99 ms 204540 KB Output is correct
38 Correct 89 ms 204496 KB Output is correct
39 Correct 83 ms 204528 KB Output is correct
40 Correct 94 ms 204616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 196172 KB Output is correct
2 Correct 73 ms 196248 KB Output is correct
3 Correct 72 ms 196132 KB Output is correct
4 Correct 79 ms 196204 KB Output is correct
5 Correct 72 ms 196252 KB Output is correct
6 Correct 75 ms 196220 KB Output is correct
7 Correct 74 ms 196248 KB Output is correct
8 Correct 85 ms 196228 KB Output is correct
9 Correct 71 ms 196172 KB Output is correct
10 Correct 72 ms 196216 KB Output is correct
11 Correct 73 ms 196276 KB Output is correct
12 Correct 71 ms 196252 KB Output is correct
13 Correct 84 ms 196288 KB Output is correct
14 Correct 75 ms 196240 KB Output is correct
15 Correct 73 ms 196300 KB Output is correct
16 Correct 76 ms 196224 KB Output is correct
17 Correct 79 ms 196304 KB Output is correct
18 Correct 74 ms 196212 KB Output is correct
19 Correct 72 ms 196212 KB Output is correct
20 Correct 75 ms 196300 KB Output is correct
21 Correct 76 ms 197384 KB Output is correct
22 Correct 73 ms 197344 KB Output is correct
23 Correct 76 ms 197372 KB Output is correct
24 Correct 74 ms 197396 KB Output is correct
25 Correct 88 ms 197336 KB Output is correct
26 Correct 73 ms 197288 KB Output is correct
27 Correct 73 ms 197316 KB Output is correct
28 Correct 73 ms 197324 KB Output is correct
29 Correct 73 ms 197284 KB Output is correct
30 Correct 76 ms 197372 KB Output is correct
31 Correct 96 ms 204576 KB Output is correct
32 Correct 96 ms 204620 KB Output is correct
33 Correct 86 ms 204588 KB Output is correct
34 Correct 86 ms 204540 KB Output is correct
35 Correct 88 ms 204592 KB Output is correct
36 Correct 84 ms 204588 KB Output is correct
37 Correct 99 ms 204540 KB Output is correct
38 Correct 89 ms 204496 KB Output is correct
39 Correct 83 ms 204528 KB Output is correct
40 Correct 94 ms 204616 KB Output is correct
41 Correct 901 ms 392808 KB Output is correct
42 Correct 757 ms 392860 KB Output is correct
43 Correct 750 ms 392864 KB Output is correct
44 Correct 695 ms 392868 KB Output is correct
45 Correct 737 ms 392844 KB Output is correct
46 Correct 693 ms 392908 KB Output is correct
47 Correct 712 ms 393032 KB Output is correct
48 Correct 803 ms 392908 KB Output is correct
49 Correct 729 ms 392908 KB Output is correct
50 Correct 700 ms 392904 KB Output is correct
51 Correct 778 ms 393024 KB Output is correct
52 Correct 684 ms 392984 KB Output is correct
53 Correct 747 ms 392796 KB Output is correct
54 Correct 691 ms 392908 KB Output is correct
55 Correct 715 ms 392908 KB Output is correct