Submission #1128251

#TimeUsernameProblemLanguageResultExecution timeMemory
1128251rasbery303Growing Vegetable is Fun 3 (JOI19_ho_t3)C++20
0 / 100
1 ms332 KiB
#include <iostream> #include <string> #include <algorithm> using namespace std; const int N = 404; int n, ans = 0; string s; int main(){ cin >> n >> s; s = '/'+ s + '/'; for (int i = 2; i <= n; ++i){ if (s[i-1] == s[i-2] && s[i]!=s[i-1]){ int j = i; while (j>=2 && s[j-1]==s[j-2]){ swap(s[j], s[j-1]); j--; ans++; } } } reverse(s.begin(), s.end()); for (int i = 2; i <= n; ++i){ if (s[i-1] == s[i-2] && s[i]!=s[i-1]){ int j = i; while (j>=2 && s[j-1]==s[j-2]){ swap(s[j], s[j-1]); j--; ans++; } } } for (int i = 2; i <= n; ++i) if (s[i]==s[i-1]) 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...