답안 #895093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895093 2023-12-29T12:14:13 Z hariaakas646 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t);
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int n;

lli dist(string &st1, string &st2) {
	int r = -1;
	int g = -1;
	int y = -1;
	lli tot = 0;
	frange(i, n) {
		if(st1[i] == 'R') {
			if(r != -1) {
				tot += i - r;
				r = -1;
			}
			else r = i;
		}
		else if(st1[i] == 'G') {
			if(g != -1) {
				tot += i - g;
				g = -1;
			}
			else g = i;
		}
		else {
			if(y != -1) {
				tot += i - y;
				y = -1;
			}
			else y = i;
		}
		if(st2[i] == 'R') {
			if(r != -1) {
				tot += i - r;
				r = -1;
			}
			else r = i;
		}
		else if(st2[i] == 'G') {
			if(g != -1) {
				tot += i - g;
				g = -1;
			}
			else g = i;
		}
		else {
			if(y != -1) {
				tot += i - y;
				y = -1;
			}
			else y = i;
		}
	}
	return tot/2;
}

int main() {
	// usaco();
	string str;
	cin >> n >> str;

	int rc = 0;
	int gc = 0;

	frange(i, n) {
		if(str[i] == 'R') rc++;
		else gc++;
	}

	if(rc == gc) {
		string str1, str2;
		frange(i, n) {
			if(i % 2) {
				str1 += 'R';
				str2 += 'G';
			}
			else {
				str1 += 'G';
				str2 += 'R';
			}
		}
		printf("%lld", min(dist(str, str1), dist(str, str2)));
	}
	else if(rc == gc+1) {
		string str1;
		frange(i, n) {
			if(i % 2==0) str1 += 'R';
			else str1 += 'G';
		}
		printf("%lld", dist(str, str1));
	}
	else if(rc == gc-1) {
		string str1;
		frange(i, n) {
			if(i % 2) str1 += 'R';
			else str1 += 'G';
		}
		printf("%lld", dist(str, str1));
	}
	else printf("-1");
}

Compilation message

joi2019_ho_t3.cpp: In function 'void usaco()':
joi2019_ho_t3.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -