| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 110388 | pamaj | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1074 ms | 18672 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(string t)
{
for(int i = 0; i < t.size(); i++)
if(t[i] == t[i + 1]) return false;
return true;
}
map<pair<int, string>, int> dp;
int solve(int num, string s)
{
if(check(s)) return dp[{num, s}] = num;
if(dp[{num, s}]) return dp[{num, s}];
int melhor = 1e9;
if(num == n) return 1e9;
for(int i = 0; i < n - 1; i++)
{
string temp = s;
swap(temp[i], temp[i + 1]);
melhor = min(melhor, solve(num + 1, temp));
}
return dp[{num, s}] = melhor;
}
int main()
{
cin >> n;
string s;
cin >> s;
int ans = solve(0, s);
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... | ||||
