답안 #819172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819172 2023-08-10T08:17:53 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

int R, G, B;
int main() {
  int N;
  cin >> N;

  char str[N];

  for (int i = 0; i < N; i++) {
    cin >> str[i];
    if (str[i] == 'R') {
      R++;
    } else if (str[i] == 'G') {
      G++;
    } else {
      B++;
    }
  }

  if (max(max(R,G), B) > (N + 1) / 2) {
    cout << -1 << endl;
    return 0;
  }
  
  int l = 1, r = 1;
  int moves = 0;
  if (B == 0) {
    // 15pts
    if (R > G) {
      if (str[0] != 'R') {
        while (str[r] == 'G') {
          r++;
        }
        swap(str[0], str[r]);
        moves += r;
      }
    } else if (R < G) {
      if (str[0] != 'G') {
        while (str[r] == 'R') {
          r++;
        }
        swap(str[0], str[r]);
        moves += r;
      }
    }
    // if same as previous go next until not same
    while (l < N) {
      if (str[l] == str[l-1]) {
        // if (r <= l) r = l + 1;
        r = l + 1;
        while (str[r] == str[l-1]) {
          r++;
        }
        swap(str[l], str[r]);
        moves += r - l;
      }
      l++;
    }
  }

  // int l = 1, r = 1;
  // int moves = 0;
  // // if same as previous go next until not same
  // while (l < N) {
  //   if (str[l] == str[l-1]) {
  //     // if (r <= l) r = l + 1;
  //     r = l + 1;
  //     while (str[r] == str[l-1]) {
  //       r++;
  //     }
  //     swap(str[l], str[r]);
  //     moves += r - l;
  //   }
  //   l++;
  // }

  cout << moves << endl;

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 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 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -