| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 497393 | Mukhitali | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 0 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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;
s[0] = 'R';
if (r != 0)
s.erase(r, 1);
}
else {
r = 0;
while (s[r] != 'G')
r++;
ans += r;
s[0] = 'G';
if (r != 0)
s.erase(r, 1);
}
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;
}
}
}
cout << ans;
}
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
