답안 #538820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538820 2022-03-17T19:52:04 Z Antekb Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
3 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
int ans;
string s;
void swa(int i){
    if(s[i]!=s[i+1]){
        swap(s[i], s[i+1]);
        ans++;
    }
}
int main(){
    int n;
    cin>>n;
    cin>>s;
    if(n==1){
        cout<<0;
        return 0;
    }
    //s='a'+s;
    for(int i=0; i<n; i++){
        if(i>=2 && (s[i-1]==s[i-2] && s[i-1]!=s[i])){
            for(int j=i-1; ;j--){
                if(j==0 || s[j]!=s[j-1]){
                    ans+=i-j-1;
                    swap(s[i], s[j+1]);
                    break;
                }
            }
        }
    }
    //cout<<s<<"\n";
    reverse(s.begin(), s.end());
    for(int i=0; i<n; i++){
        if(i>=2 && (s[i-1]==s[i-2] && s[i-1]!=s[i])){
            for(int j=i-1; ; j--){
                if(j==0 || s[j]!=s[j-1]){
                    ans+=i-j-1;
                    swap(s[i], s[j+1]);
                    break;
                }
            }
        }
    }
    //cout<<s<<"\n";
    if(s[n-1]==s[n-2])cout<<"-1";
    else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -