Submission #720985

#TimeUsernameProblemLanguageResultExecution timeMemory
720985PringGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
15 / 100
1 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; const int MXN = 405; int n; string s; vector<int> R, G; int SOLVE0() { // RGRG...RGRGR int ans = 0; for (int i = 0; i < n / 2; i++) { ans += abs(i * 2 + 1 - G[i]); } return ans; } int SOLVE1() { // RGRG...RGRG, GRGR...GRGR int ans0 = 0, ans1 = 0; for (int i = 0; i < n / 2; i++) { ans0 += abs(i * 2 + 1 - G[i]); ans1 += abs(i * 2 + 1 - R[i]); } return min(ans0, ans1); } int SOLVE2() { // GRGR...GRGRG int ans = 0; for (int i = 0; i < n / 2; i++) { ans += abs(i * 2 + 1 - R[i]); } return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'R') R.push_back(i); else if (s[i] == 'G') G.push_back(i); else return 0; } if (R.size() == G.size() + 1) cout << SOLVE0() << endl; else if (R.size() == G.size()) cout << SOLVE1() << endl; else if (R.size() + 1 == G.size()) cout << SOLVE2() << endl; else cout << -1 << 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...