# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110440 | luciocf | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 3 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 410;
char a[maxn], b[maxn];
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf(" %c", &a[i]);
b[i] = a[i];
}
int ans = 0, Ans = 1e9+10;
bool ok = 1;
for (int i = 0; i < n; i++)
{
if ( (i%2 == 0 && b[i] == 'G') || (i%2 == 1 && b[i] == 'R'))
{
ok = 0;
break;
}
bool found = 0;
for (int j = i+1; j < n; j++)
{
if (i%2 == 0 && j%2 == 1 && b[j] == 'G')
{
found = 1;
ans += (j-i);
swap(b[i], b[j]);
break;
}
else if (i%2 == 1 && j%2 == 0 && b[j] == 'R')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
}
if (!found)
{
ok = 0;
break;
}
}
if (ok)
Ans = max(Ans, ans);
ok = 1, ans = 0;
for (int i = 0; i < n; i++)
b[i] = a[i];
for (int i = 0; i < n; i++)
{
if ( (i%2 == 0 && b[i] == 'R') || (i%2 == 1 && b[i] == 'G'))
{
ok = 0;
break;
}
bool found = 0;
for (int j = i+1; j < n; j++)
{
if (i%2 == 0 && j%2 == 1 && b[j] == 'R')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
else if (i%2 == 1 && j%2 == 0 && b[j] == 'G')
{
found = 1;
ans += j-i;
swap(b[i], b[j]);
break;
}
}
if (!found)
{
ok = 0;
break;
}
}
if (ok)
Ans = max(ans, Ans);
if (Ans == 1e9+10)
printf("-1\n");
else
printf("%d\n", Ans);
}
컴파일 시 표준 에러 (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... |