Submission #872780

#TimeUsernameProblemLanguageResultExecution timeMemory
872780scrgeGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1064 ms600 KiB
#include <bits/stdc++.h> using namespace std; signed main(){ int n; cin >> n; string s; cin >> s; map<char, vector<int>> pos; for(int i = 0; i < n; i++) pos[s[i]].push_back(i); auto check = [&](string t) -> int{ int res = 0; map<char, int> ind; ind['R']=0, ind['G']=0, ind['Y']=0; for(int i = 0; i < n; i++){ if(i < n-1) if(t[i] == t[i+1]) return 1e9; res += abs(i-pos[t[i]][ind[t[i]]++]); } return res; }; int ans = 1e9; sort(begin(s), end(s)); ans = min(ans, check(s)); while(next_permutation(begin(s), end(s))){ ans = min(ans, check(s)); //cout << s << " " << ans << endl; } cout << (ans == 1e9 ? -1 : ans/2) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...