답안 #1108077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108077 2024-11-02T17:06:37 Z overwatch9 Group Photo (JOI21_ho_t3) C++17
5 / 100
5000 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector <int> nums(n), pos(n+1);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
        pos[nums[i]] = i;
    }
    int ans = 1e9;
    vector <int> nums2(n);
    for (int i = 0; i < n; i++)
        nums2[i] = i+1;
    do {
        int cost = 0;
        bool valid = true;
        for (int i = 0; i+1 < n; i++) {
            if (nums2[i] >= nums2[i+1] + 2)
                valid = false;
        }
        if (!valid)
            continue;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (pos[nums2[i]] > pos[nums2[j]])
                    cost++;
            }
        }
        ans = min(ans, cost);
    } while (next_permutation(nums2.begin(), nums2.end()));
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 436 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 436 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Execution timed out 5060 ms 336 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 436 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Execution timed out 5060 ms 336 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 436 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Execution timed out 5060 ms 336 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 4 ms 336 KB Output is correct
8 Correct 4 ms 336 KB Output is correct
9 Correct 4 ms 436 KB Output is correct
10 Correct 4 ms 336 KB Output is correct
11 Execution timed out 5060 ms 336 KB Time limit exceeded
12 Halted 0 ms 0 KB -