Submission #1128232

#TimeUsernameProblemLanguageResultExecution timeMemory
1128232rasbery303Growing Vegetable is Fun 3 (JOI19_ho_t3)C++20
0 / 100
0 ms328 KiB
#include <iostream> #include <string> using namespace std; int n, cnt = 1, ans = 0; string s; int main(){ cin >> n >> s; s = '/'+s; for (int i = 1; i <= n; ++i){ if (s[i]!=s[i-1]){ if (cnt==1) continue; else { int j = i; for (int k = 1; k < cnt; ++k, --j) swap(s[j], s[j-1]); ans += --cnt; } } else { cnt++; } } if (cnt==2) ans++; if (cnt>2) ans = -1; cout << ans; 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...