Submission #819135

#TimeUsernameProblemLanguageResultExecution timeMemory
819135vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<int, int> #define pb push_back #define fi first #define se second using namespace std; const int MX=450; int n, pref[MX], ans; char c[MX]; int main(){ cin >> n; for(int i=1; i<=n; i++){ cin >> c[i]; } for(int i=1; i<n; i++){ // cout << i << endl; if(c[i]!=c[i+1])continue; int idx=i; while(idx<=n && c[idx]==c[i]){ idx++; } // cout << idx << " " << i+1 <<endl; if(idx>n) break; ans+=idx-(i+1); swap(c[idx], c[i+1]); // for(int j=1; j<=n; j++) cout << c[j]; cout << endl; } for(int i=n; i>=2; i--){ // cout << i << endl; if(c[i]!=c[i-1])continue; int idx=i; while(idx>=1 && c[idx]==c[i]){ idx--; } // cout << idx << " " << i-1 <<endl; if(idx<1) break; ans+=(i-1)-idx; swap(c[idx], c[i-1]); // for(int j=1; j<=n; j++) cout << c[j]; cout << endl; } //cek for(int i=2; i<=n; i++){ if(c[i]==c[i-1]){ cout << -1 << endl; return 0; } } cout << ans << 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...