답안 #136801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136801 2019-07-26T09:28:53 Z SirCeness Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x << " "
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define ppair(x) "(" << x.first << ", " << x.second << ")"
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl

typedef long long ll;

int main(){
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	
	int n;
	cin >> n;
	string s;
	cin >> s;

	int fazla = 0;
	char son = s[0];
	ll ans = 0;
	string yeni;
	yeni += son;
	for (int i = 1; i < n; i++){
		//cout << bas(i) << endl;
		//cout << bas(fazla) << endl;
		if (fazla == 0){
			if (son == s[i]) fazla++;
			else {
				son = s[i];
				yeni += s[i];
			}
		} else {
			if (son == s[i]) fazla++;
			else {
				ans += fazla;
				fazla--;
				yeni += s[i];
				yeni += son;
			}
		}
		//cout << bas(fazla) << endl;
	}
	while (fazla--) yeni += son;
	
	reverse(yeni.begin(), yeni.end());
	//cout << yeni << endl;
	//cout << ans << endl;

	fazla = 0;
	son = yeni[0];
	
	for (int i = 1; i < n; i++){
		//cout << bas(i) << endl;
		//cout << bas(fazla) << endl;
		if (fazla == 0){
			if (son == yeni[i]) fazla++;
			else {
				son = yeni[i];
			}
		} else {
			if (son == yeni[i]) fazla++;
			else {
				ans += fazla;
				fazla--;
			}
		}
		//cout << bas(fazla) << endl;
	}

	if (fazla != 0) cout << -1;
	else cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -