Submission #670529

#TimeUsernameProblemLanguageResultExecution timeMemory
670529MilosMilutinovicGroup Photo (JOI21_ho_t3)C++14
5 / 100
5038 ms324 KiB
#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; }
#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...