Submission #1108076

#TimeUsernameProblemLanguageResultExecution timeMemory
1108076overwatch9Group Photo (JOI21_ho_t3)C++17
0 / 100
1 ms436 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector <int> nums(n), pos(n); 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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...