Submission #659168

#TimeUsernameProblemLanguageResultExecution timeMemory
659168KenparGrowing 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 endl '\n' const ll MOD = 1e9+7; const ll INF = 1e16; const ll MAX = 2 * 1e5; void solve(){ int n; cin>>n; string temp; cin>>temp; int r=0,g=0,y=0; vector<char> arr; for(char c : temp){ if(c == 'R') r++; else if(c == 'G') g++; else y++; arr.push_back(c); } if(max(r, max(g, y)) > (n+1)/2){ cout<<-1; return; } int ans = 0; for(int i = 2; i < n; i++){ for(int j = 0; j < i-1; j++){ if(arr[j] == arr[j+1] && arr[j] != arr[i]){ ans+= i - j - 1; char c = arr[i]; arr.erase(next(arr.begin(), i)); arr.insert(next(arr.begin(),j+1), c); } } } for(int i = n-3; i >= 0; i--){ for(int j = n-1; j > i+1; j--){ if(arr[j] == arr[j-1] && arr[j] != arr[i]){ ans+= j - i - 1; char c = arr[i]; arr.erase(next(arr.begin(), i)); arr.insert(next(arr.begin(),j-1), c); } } } cout<<ans; } int main() { cin.tie(NULL); ios::sync_with_stdio(NULL); int t = 1; //cin >> t; while(t--){ //cout<<"Case #"<<t<<" > "<<endl; solve(); cout<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...