답안 #960274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960274 2024-04-10T06:29:35 Z mickytanawin Group Photo (JOI21_ho_t3) C++17
100 / 100
272 ms 97896 KB
// Tanawin Thongbai

#include <bits/extc++.h>
using namespace std;


const int N = 5000;

int orig[N + 1], indices[N + 1], obstruct[N + 1], obstructed[N + 1], obstructed_at[N + 1], dp_L[N + 1][N + 1], dp[N + 1];


int main() {
    int n_elem;
    scanf("%d", &n_elem);
    for(int i = 1; i <= n_elem; ++i) {
        scanf("%d", &orig[i]);
        indices[orig[i]] = i;
    }
    for(int j = 1; j <= n_elem; ++j) {
        dp_L[j][j] = 0;
        int mv = 0;
        for(int i = j - 1; i >= 1; --i) {
            if(indices[i] < indices[j]) {
                ++mv;
            }
            dp_L[i][j] = dp_L[i][j - 1] + mv;
        }
    }
    for(int i = 1; i <= n_elem; ++i) {
        for(int j = indices[i] + 1; j <= n_elem; ++j) {
            if(orig[j] < i) {
                ++obstruct[i];
            }
        }
        for(int j = indices[i] - 1; j >= 1; --j) {
            if(orig[j] > i) {
                ++obstructed[i];
            }
        }
    }
    for(int i = 1; i <= n_elem; ++i) {
        int mn = 1e9;
        int mv = 0;
        int k = n_elem + 1;
        int cnt = 0;
        for(int j = 1; j <= n_elem; ++j) {
            obstructed_at[j] = cnt;
            if(orig[j] > i) {
                ++cnt;
            }
        }
        for(int j = i; j >= 1; --j) {
            if(indices[j] > k) {
                mv += obstruct[j] - obstructed[j] + obstructed_at[indices[j]];
            } else {
                mv += obstruct[j];
            }
            if(indices[j] < k) {
                k = indices[j];
            }
            mn = min(mn, dp[j - 1] + dp_L[j][i] + mv);
        }
        dp[i] = mn;
    }
    printf("%d\n", dp[n_elem]);

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d", &n_elem);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d", &orig[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2488 KB Output is correct
9 Correct 3 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2488 KB Output is correct
9 Correct 3 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2488 KB Output is correct
9 Correct 3 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 5 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2488 KB Output is correct
9 Correct 3 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 5 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4540 KB Output is correct
31 Correct 5 ms 16728 KB Output is correct
32 Correct 6 ms 16732 KB Output is correct
33 Correct 6 ms 16948 KB Output is correct
34 Correct 7 ms 16948 KB Output is correct
35 Correct 6 ms 16732 KB Output is correct
36 Correct 5 ms 16732 KB Output is correct
37 Correct 5 ms 16944 KB Output is correct
38 Correct 6 ms 16732 KB Output is correct
39 Correct 6 ms 16732 KB Output is correct
40 Correct 6 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2488 KB Output is correct
9 Correct 3 ms 2392 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 5 ms 4440 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4540 KB Output is correct
31 Correct 5 ms 16728 KB Output is correct
32 Correct 6 ms 16732 KB Output is correct
33 Correct 6 ms 16948 KB Output is correct
34 Correct 7 ms 16948 KB Output is correct
35 Correct 6 ms 16732 KB Output is correct
36 Correct 5 ms 16732 KB Output is correct
37 Correct 5 ms 16944 KB Output is correct
38 Correct 6 ms 16732 KB Output is correct
39 Correct 6 ms 16732 KB Output is correct
40 Correct 6 ms 16732 KB Output is correct
41 Correct 272 ms 97416 KB Output is correct
42 Correct 230 ms 97364 KB Output is correct
43 Correct 247 ms 97416 KB Output is correct
44 Correct 240 ms 97360 KB Output is correct
45 Correct 249 ms 97616 KB Output is correct
46 Correct 230 ms 97268 KB Output is correct
47 Correct 240 ms 97360 KB Output is correct
48 Correct 231 ms 97896 KB Output is correct
49 Correct 236 ms 97360 KB Output is correct
50 Correct 228 ms 97660 KB Output is correct
51 Correct 242 ms 97620 KB Output is correct
52 Correct 231 ms 97292 KB Output is correct
53 Correct 238 ms 97400 KB Output is correct
54 Correct 234 ms 97652 KB Output is correct
55 Correct 247 ms 97320 KB Output is correct