# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
555384 | LucaDantas | Group Photo (JOI21_ho_t3) | C++17 | 3 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 11;
int a[maxn], b[maxn];
bool mark[maxn];
bool valid(int n) {
for(int i = 1; i < n; i++)
if(b[i] + 2 <= b[i-1])
return 0;
return 1;
}
int get(int n) {
memset(mark, 1, sizeof mark);
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; a[j] != b[i]; j++)
ans += mark[a[j]];
mark[b[i]] = 0;
}
return ans;
}
int main() {
int n; scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
iota(b, b+n, 1);
int ans = 0x3f3f3f3f;
do {
if(valid(n))
ans = min(ans, get(n));
} while(next_permutation(b, b+n));
printf("%d\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |