답안 #497387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497387 2021-12-23T04:12:25 Z Mukhitali Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 316 KB
//bit chass 1
#include <bits/stdc++.h>

#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;

const int N = 1e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;

void solve() {
	int n, k = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++)
		if (s[i] == 'R')
			k++;
	if (k > (n + 1) / 2 || (n - k) > (n + 1) / 2)
		cout << -1;
	else {
		int r = 2;
		ll ans = 0;
		if (n % 2 == 0) {
			for (int i = 1; i < s.size(); i++) {
				r = max(r, i + 1);
				if (s[i] == s[i - 1]) {
					while (s[r] == s[i - 1])
						r++;
					s.erase(r, 1);
					ans += r - i;
				}
			}
		}
		else {
			if (k == n / 2 + 1) {
				r = 0;
				while (s[r] != 'R')
					r++;
				ans += r;
				for (int i = 1; i < s.size(); i++) {
					r = max(r, i + 1);
					if (s[i] == s[i - 1]) {
						while (s[r] == s[i])
							r++;
						s.erase(r, 1);
						ans += r - i;
					}
				}
			}
			else {
				
			}
		}
		cout << ans;
	}
	
}

int main() {
	ibase;
	int T = 1;
//	cin >> T;
	for (int i = 1; i <= T; i++) {
//		cout << "Case " << i << ": ";
		solve();
		cout << el;
	}
}

Compilation message

joi2019_ho_t3.cpp: In function 'void solve()':
joi2019_ho_t3.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for (int i = 1; i < s.size(); i++) {
      |                    ~~^~~~~~~~~~
joi2019_ho_t3.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 1; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -