Submission #818983

#TimeUsernameProblemLanguageResultExecution timeMemory
818983vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define endl "\n" #define pii pair<ll,ll> #define pb push_back #define vi vector<ll> #define pque priority_queue #define pqueg priority_queue<ll,vector<ll>,greater<ll>> #define que queue<ll> #define FOR(m,i,n) for(int i=(m); i<=(n); i++) #define FORM(m,i,n) for(int i=(m); i>=(n); i--) #define all(v) sort(v.begin(),v.end()) ll n,ans,r,g; string s; int main() { // char c = 'R' ^ 'L' ^ 'R'; // cout << c << endl; ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s; s = '!' + s; FOR(1,i,n) { if(s[i] == 'R') r++; else g++; } if(abs(r-g) > 1) { cout << -1 << endl; return 0; } if(r == g || (r > g && s[1] == 'R') || (g > r && s[1] == 'G')) { FOR(2,i,n) { if(s[i] == s[i-1]) { FOR(i+1,j,n) { if(s[j] != s[i]) { FORM(j,k,i+1) { swap(s[k],s[k-1]); ans++; } break; } } } } } else { char now = 'R' ^ 'G' ^ s[1]; FOR(1,i,n) { if(s[i] != now) { FOR(i+1,j,n) { if(s[j] == now) { FORM(j,k,i+1) { swap(s[k],s[k-1]); ans++; } break; } } } now = s[i] ^ 'R' ^ 'G'; } } cout << ans << endl; } /* 5 GGGRR 7 GGRRGRR */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...