| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1291514 | MrDogMeat | Giraffes (JOI22_giraffes) | C++20 | 2 ms | 576 KiB |
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 8e3;
const int INF32 = 1e9;
///vector
#define SZ(x) (int)x.size()
///input
int N;
int P[MAXN+5];
namespace sub1 {
int Ans = INF32;
bool check(const vector<int>& P) {
for(int l = 0; l < N; l++)
{
for(int r = 0; r < N; r++)
{
bool cond1 = false, cond2 = false;
for(int i = l; i <= r; i++)
{
if(P[i] > P[l] && P[i] > P[r]) cond1 = true;
if(P[i] < P[l] && P[i] < P[r]) cond2 = true;
}
if(cond1 && cond2) return false;
}
}
return true;
}
void solution() {
vector<int> perm(N);
for(int i = 0; i < N; i++) {
perm[i] = i + 1;
}
do {
if(check(perm)) {
int cnt = 0;
for(int i = 1; i <= N; i++) {
if(P[i] != perm[i - 1]) cnt++;
}
Ans = min(Ans, cnt);
}
} while(next_permutation(perm.begin(), perm.end()));
cout << Ans;
}
bool check() {
return (N <= 7);
}
}
void solution() {
cin >> N;
for(int i = 1; i <= N; i++) {
cin >> P[i];
}
if(sub1::check()) return sub1::solution();
}
#define FILE "task"
main() {
if(fopen(FILE".in","r")) {
freopen(FILE".in","r",stdin);
freopen(FILE".ans","w",stdout);
}
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
solution();
cerr << "\n" << clock() << " ms";
return 0;
}
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... | ||||
