답안 #670529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670529 2022-12-09T13:39:42 Z MilosMilutinovic Group Photo (JOI21_ho_t3) C++14
5 / 100
5000 ms 324 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];
    --h[i];
  }
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    pos[h[i]] = i;
  }
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  int ans = 1e9;
  do {
    bool valid = true;
    for (int i = 0; i + 1 < n; i++) {
      valid = (valid & (p[i] < p[i + 1] || p[i] == p[i + 1] + 1));
    }
    if (!valid) {
      continue;
    }
    int nans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (pos[p[i]] > pos[p[j]]) {
          nans += 1;
        }
      }
    }
    ans = min(ans, nans);
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 7 ms 324 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 7 ms 212 KB Output is correct
10 Correct 7 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 7 ms 324 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 7 ms 212 KB Output is correct
10 Correct 7 ms 320 KB Output is correct
11 Execution timed out 5038 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 7 ms 324 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 7 ms 212 KB Output is correct
10 Correct 7 ms 320 KB Output is correct
11 Execution timed out 5038 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 7 ms 324 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 7 ms 212 KB Output is correct
10 Correct 7 ms 320 KB Output is correct
11 Execution timed out 5038 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 7 ms 324 KB Output is correct
8 Correct 7 ms 212 KB Output is correct
9 Correct 7 ms 212 KB Output is correct
10 Correct 7 ms 320 KB Output is correct
11 Execution timed out 5038 ms 212 KB Time limit exceeded
12 Halted 0 ms 0 KB -