답안 #670556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670556 2022-12-09T14:19:27 Z MilosMilutinovic Group Photo (JOI21_ho_t3) C++14
44 / 100
5000 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<int> pos(n + 1);
  for (int i = 0; i < n; i++) {
    pos[h[i]] = i;
  }
  const int inf = 1e9;
  vector<int> dp(n + 1, inf);
  dp[0] = 0;
  auto Solve = [&](int L, int R) {
    int res = 0;
    for (int i = L; i <= R; i++) {
      for (int j = 1; j < L; j++) {
        if (pos[i] < pos[j]) {
          res += 1;
        }
      }
    }
    for (int i = L; i <= R; i++) {
      for (int j = L; j < i; j++) {
        if (pos[i] > pos[j]) {
          res += 1;
        }
      }
    }
    return res;
  };
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dp[j] = min(dp[j], dp[i] + Solve(i + 1, j));
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 97 ms 304 KB Output is correct
22 Correct 101 ms 212 KB Output is correct
23 Correct 100 ms 320 KB Output is correct
24 Correct 100 ms 304 KB Output is correct
25 Correct 102 ms 300 KB Output is correct
26 Correct 103 ms 324 KB Output is correct
27 Correct 99 ms 212 KB Output is correct
28 Correct 99 ms 212 KB Output is correct
29 Correct 99 ms 304 KB Output is correct
30 Correct 98 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 97 ms 304 KB Output is correct
22 Correct 101 ms 212 KB Output is correct
23 Correct 100 ms 320 KB Output is correct
24 Correct 100 ms 304 KB Output is correct
25 Correct 102 ms 300 KB Output is correct
26 Correct 103 ms 324 KB Output is correct
27 Correct 99 ms 212 KB Output is correct
28 Correct 99 ms 212 KB Output is correct
29 Correct 99 ms 304 KB Output is correct
30 Correct 98 ms 212 KB Output is correct
31 Execution timed out 5042 ms 212 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 97 ms 304 KB Output is correct
22 Correct 101 ms 212 KB Output is correct
23 Correct 100 ms 320 KB Output is correct
24 Correct 100 ms 304 KB Output is correct
25 Correct 102 ms 300 KB Output is correct
26 Correct 103 ms 324 KB Output is correct
27 Correct 99 ms 212 KB Output is correct
28 Correct 99 ms 212 KB Output is correct
29 Correct 99 ms 304 KB Output is correct
30 Correct 98 ms 212 KB Output is correct
31 Execution timed out 5042 ms 212 KB Time limit exceeded
32 Halted 0 ms 0 KB -