# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110402 | pamaj | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 60 ms | 384 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;
const int maxn = 410;
int n;
bool check(vector<pair<char, int>> &t)
{
for(int i = 0; i < t.size() - 1; i++)
if(t[i].first == t[i + 1].first) return false;
return true;
}
int main()
{
cin >> n;
vector<pair<char, int>> s, t;
for(int i = 0; i < n; i++)
{
char c;
cin >> c;
s.push_back({c, i});
}
t = s;
sort(s.begin(), s.end());
int ans = 1e9;
do
{
if(check(s))
{
int num_dif = 0;
for(int i = 0; i < n; i++)
if(s[i].second != t[i].second) num_dif++;
ans = min(ans, num_dif);
}
} while(next_permutation(s.begin(), s.end()));
cout << (ans == (int)1e9 ? -1 : ans) << "\n";
}
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... |