# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
555384 | LucaDantas | Group Photo (JOI21_ho_t3) | C++17 | 3 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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... |