| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1128251 | rasbery303 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++20 | 1 ms | 332 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 time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
