Submission #938156

#TimeUsernameProblemLanguageResultExecution timeMemory
938156LittleOrangeGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(0);cin.tie(0); ll n; string s; cin >> n >> s; vector<ll> cnt(3,0); vector<ll> a(n); for(ll i = 0;i<n;i++) { a[i] = s[i]=='R'?0:s[i]=='G'?1:2; cnt[a[i]]++; } ll ans = 0; for(ll i = 1;i<n;i++){ if(s[i]==s[i-1]){ ll j = i+1; while(s[j]==s[i]&&j<n-1) j++; if (s[j]==s[i]){ cout << "-1\n"; return 0; } ans += j-i; for(ll k = j;k>i;k--) swap(s[k],s[k-1]); } } for(ll i = 1;i<n;i++){ if(s[i]==s[i-1]){ cout << "-1\n"; return 0; } } cout << ans << "\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...