답안 #819361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819361 2023-08-10T09:43:33 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
#define all(v) sort(v.begin(),v.end())
ll n,ans,r,g;
string s,s1;
char now;
vector<ll> rr,gg;
int main() {
//	cout << pow(2,15) << endl;
//	char c = 'R' ^ 'L' ^ 'R';
//	cout << c << endl;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	s = '!' + s;
	FOR(1,i,n) {
		if(s[i] == 'R') r++;
		else g++;
	}
	if(abs(r-g) > 1) {
		cout << -1 << endl;
		return 0;
	}
	if(r > g) now = 'R';
	else if(g > r) now = 'G';
	else now = s[1]; 
	s1 += '!';
	FOR(1,i,n) {
		s1 += now;
		now = now ^ 'R' ^ 'G';
	}
	FOR(1,i,n) {
		if(s[i] != s1[i]) {
			if(s[i] == 'R') rr.pb(i);
			else gg.pb(i);
		}
	}
	all(gg); all(rr);
	if((ll)gg.size() != (ll)rr.size()) {
		cout << -1 << endl;
	}
	FOR(0,i,(ll)gg.size()-1) {
		ans += abs(gg[i] - rr[i]);
	}
	cout << ans << endl;
}

/*
5
GGGRR

7
GGRRGRR

7
GRGGRRR
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 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 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -