답안 #1107327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107327 2024-11-01T06:17:16 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;

void abb(){
    int n, ans = 0;
    cin >> n;
    string s; cin >> s;
    int r = 0, g = 0, y = 0;
    for (int i = 0; i < s.size(); ++i){
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else y++;
    }if (r + g < y || y + g < r || r + y < g){
        cout << "-1\n"; return;
    }for (int i = 0; i < s.size(); ++i){
        if (s[i] == s[i + 1]){
            int j = i + 1;
            while(j < s.size() && s[j] == s[i]) j++;
            // cout << j << " " << i << " " << s[i] << " " << s[j] << "\n";
            swap(s[i + 1], s[j]); ans += j - i - 1;
        }
    }cout << ans << "\n";
}

signed main(){
    int T = 1;
    // cin >> T;
    while(T--){
        abb();
    }
}



// 5 6
// - - - - - -
// - - - - - -
// - - - - - -
// - - + + + +
// + + + + - -






Compilation message

joi2019_ho_t3.cpp: In function 'void abb()':
joi2019_ho_t3.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < s.size(); ++i){
      |                     ~~^~~~~~~~~~
joi2019_ho_t3.cpp:15:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     }for (int i = 0; i < s.size(); ++i){
      |                      ~~^~~~~~~~~~
joi2019_ho_t3.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             while(j < s.size() && s[j] == s[i]) j++;
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -