제출 #1130112

#제출 시각아이디문제언어결과실행 시간메모리
1130112am_aadvikGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++20
15 / 100
0 ms328 KiB
#include <iostream> #include<vector> using namespace std; string alt(int n, bool c) { string ans = ""; while (n--) ans += "RG"[c], c ^= 1; return ans; } int sol(string s, string t) { //s->t int n = s.length(), ans = 0; for (int i = 0; i < n; ++i) if (s[i] != t[i]) { int val = 0; for(int j = i + 1; j < n; ++j) if (s[j] == t[i]) { val = j; break; } ans += val - i, swap(s[i], s[val]); } return ans; } int32_t main() { int n, r = 0, g = 0; cin >> n; string s, a1 = alt(n, 0), a2 = alt(n, 1); cin >> s; for (int i = 0; i < n; ++i) if (s[i] == 'R') r++; else g++; if (abs(g - r) > 1) {cout << -1; return 0;} int ans = 1e8; if (g >= r) ans = min(ans, sol(s, a2)); if (r >= g) ans = min(ans, sol(s, a1)); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...