답안 #380814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380814 2021-03-23T04:56:15 Z anonymous Group Photo (JOI21_ho_t3) C++14
100 / 100
649 ms 98700 KB
#include <iostream>
#define MAXN 5005
using namespace std;

int N, H[MAXN], pos[MAXN];
int psum[MAXN][MAXN],dp[MAXN];

int main() {
    scanf("%d",&N);
    for (int i=1; i<=N; i++) {
        scanf("%d",&H[i]);
        pos[H[i]] = i;
    }
    //do prefix sum
    for (int i=1; i <= N; i++) {
        for (int h=1; h <= N; h++) {
            psum[i][h] = psum[i-1][h] + psum[i][h-1] + (H[i] == h) - psum[i-1][h-1];
        }
    }

    //dp
    for (int i=N-1; i>=1; i--) {
        dp[i] = 1<<30; //subsequence i...N
        int cost = 0;
        for (int j=i; j <= N; j++) {
            cost += 2*(psum[pos[j]][j-1]-psum[pos[j]][i-1])-(j-i)+(psum[pos[j]][N]-psum[pos[j]][j]);
            dp[i] = min(dp[i], dp[j+1] + cost);
        }
    }

    printf("%d",dp[1]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
Main.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |         scanf("%d",&H[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 2 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 2 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 10 ms 5996 KB Output is correct
32 Correct 10 ms 5996 KB Output is correct
33 Correct 10 ms 5996 KB Output is correct
34 Correct 10 ms 6124 KB Output is correct
35 Correct 10 ms 6124 KB Output is correct
36 Correct 12 ms 6124 KB Output is correct
37 Correct 10 ms 6124 KB Output is correct
38 Correct 10 ms 6124 KB Output is correct
39 Correct 10 ms 6124 KB Output is correct
40 Correct 10 ms 6124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 2 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1260 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 10 ms 5996 KB Output is correct
32 Correct 10 ms 5996 KB Output is correct
33 Correct 10 ms 5996 KB Output is correct
34 Correct 10 ms 6124 KB Output is correct
35 Correct 10 ms 6124 KB Output is correct
36 Correct 12 ms 6124 KB Output is correct
37 Correct 10 ms 6124 KB Output is correct
38 Correct 10 ms 6124 KB Output is correct
39 Correct 10 ms 6124 KB Output is correct
40 Correct 10 ms 6124 KB Output is correct
41 Correct 609 ms 98340 KB Output is correct
42 Correct 628 ms 98412 KB Output is correct
43 Correct 627 ms 98412 KB Output is correct
44 Correct 610 ms 98412 KB Output is correct
45 Correct 612 ms 98540 KB Output is correct
46 Correct 619 ms 98540 KB Output is correct
47 Correct 617 ms 98284 KB Output is correct
48 Correct 623 ms 98412 KB Output is correct
49 Correct 614 ms 98700 KB Output is correct
50 Correct 649 ms 98528 KB Output is correct
51 Correct 618 ms 98284 KB Output is correct
52 Correct 636 ms 98412 KB Output is correct
53 Correct 609 ms 98412 KB Output is correct
54 Correct 621 ms 98284 KB Output is correct
55 Correct 641 ms 98284 KB Output is correct