제출 #1128232

#제출 시각아이디문제언어결과실행 시간메모리
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...