Submission #1089324

#TimeUsernameProblemLanguageResultExecution timeMemory
1089324vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
15 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define sz size() #define yes "YES" #define no "NO" #define IOI ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pf push_front #define pb push_back #define S second #define F first using namespace std; const int N = 200 + 5; const int NN = 1e5; const int mod = (1e9 + 7); const int inf = 1e18; int R, G; void legenda_ne_umret() { int n; cin >> n; string s, ss; cin >> s; ss = s; for (int i = 0; i < n; i++) { if (s[i] == 'R') R++; if (s[i] == 'G') G++; } int ans1 = inf, ans = inf; if (abs (R - G) > 1) { cout << -1; return; } if(R >= G){ ans = 0; for(int i = 0 ; i < n ; i++){ if(i % 2 == 0){ for(int j = i; j < n ; j++){ if(s[j] == 'R'){ ans += (j - i); swap(s[i] , s[j]); break; } } } else{ for(int j = i ; j < n ; j++){ if(s[j] == 'G'){ ans += (j - i); swap(s[i] , s[j]); break; } } } } } if(G >= R){ ans1 = 0; s = ss; for(int i = 0 ; i < n ; i++){ if(i % 2){ for(int j = i ; j < n ; j++){ if(s[j] == 'R'){ ans1 += (j - i); swap(s[i] , s[j]); break; } } } else{ for(int j = i ; j < n ; j++){ if(s[j] == 'G'){ ans1 += (j - i); swap(s[i] , s[j]); break; } } } } } cout << min(ans1 , ans); } signed main() { IOI; // freopen("maze.in", "r", stdin); // freopen("maze.out", "w", stdout); ///////////////////////////////////////////// int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case " << i << ":\n"; legenda_ne_umret(); cout << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...