Submission #1127246

#TimeUsernameProblemLanguageResultExecution timeMemory
1127246elojGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++20
0 / 100
0 ms328 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int R = 0, G = 0, Y = 0; for (char c : s) { if (c == 'R') R++; else if (c == 'G') G++; else if (c == 'Y') Y++; } if (R>(n + 1)/2|| G>(n + 1)/2 || Y>(n + 1)/2) { cout << -1 << endl; return 0; } int ans = 0; for (int i = 0; i < n - 1; ++i) { if (s[i] == s[i + 1]) { for (int j = i + 1; j < n; ++j) { if (s[j] != s[i]) { swap(s[i + 1], s[j]); ans += (j - (i + 1)); break; } } } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...