답안 #883021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883021 2023-12-04T12:08:22 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
15 / 100
1 ms 756 KB
#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;

int solve(int target, vector<int> v){
	int ret = 0;
	for(int i = 0; i < v.size(); i++){
		target ^=1;
		if(v[i] == target) continue;
		int j;
		for(j = 1; i+j < v.size(); j++){
			if(v[i+j] == target){
				v[i+j]^=1;
				break;
			}
		}
		ret+=j;
	}
	return ret;
}

int main(){
	int n, cnt = 0;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		char c; cin >> c;
		v[i] = (c=='R');
		cnt += v[i];
	}

	if(cnt > (n+1)/2 || (n-cnt) > (n+1)/2){
		cout << -1;
		exit(0);
	}
	if(n > 2*cnt){
		for(int i = 0; i < n; i++) v[i] ^=1;
		cnt = n - cnt;
	}

	int ans = solve(0, v);
	if(!(n&1)) ans = min(ans, solve(1, v));
	
	cout << ans << endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int solve(int, std::vector<int>)':
joi2019_ho_t3.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
joi2019_ho_t3.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(j = 1; i+j < v.size(); j++){
      |              ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 756 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 756 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 756 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -