답안 #121158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121158 2019-06-26T07:19:06 Z 윤교준(#2970) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
#define INF (0x3f3f3f3f)
using namespace std;

char A[555];

int N, Ans = INF;

void solve() {
	int ret = 0;
	for(int i = 1, j; i <= N; i++) {
		char c = (i&1) ? 'R' : 'G';
		if(A[i] == c) continue;
		for(j = i+1; j <= N && A[j] != c; j++);
		if(N < j) return;
		swap(A[i], A[j]);
		ret += j-i;
	}
	if(ret < Ans) Ans = ret;
}

int main() {
	scanf("%d %s", &N, A+1);

	solve();
	for(int i = 1; i <= N; i++) A[i] ^= 'R'^'G';
	solve();

	cout << (INF <= Ans ? -1 : Ans) << endl;
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s", &N, A+1);
  ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -