# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
574921 | MateGiorbelidze | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1 ms | 1236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define sc second
#define pb push_back
#define in insert
int main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n; cin>>n;
string s; cin>>s;
ll a[n + 1] , r = 0 , g = 0, y = 0;
ll rp[401], rg[401], ry[401];
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R') {
r++;
rp[r] = i + 1;
}
if (s[i] == 'G') {
g++;
rg[g] = i + 1;
}
if (s[i] == 'Y') {
y++;
ry[y] = i + 1;
}
}
ll d[r + 1][g + 1][y + 1][3];
//cout<<r<<" "<<g<<" "<<y;
for (int i = 0; i <= r; i++)
for (int j = 0; j <= g; j++)
for (int k = 0; k <= y; k++)
d[i][j][k][0] = d[i][j][k][1] = d[i][j][k][2] = INT_MAX;
d[0][0][0][0] = d[0][0][0][1] = d[0][0][0][2] = 0;
for (int i = 0; i <= r; i++)
for (int j = 0; j <= g; j++)
for (int k = 0; k <= y; k++) {
if (k != 0) {
d[i][j][k][2] = min(d[i][j][k - 1][1] , d[i][j][k - 1][0]);
d[i][j][k][2] += abs(ry[k] - i - j - k);
}
if (j != 0) {
d[i][j][k][1] = min(d[i][j - 1][k][2] , d[i][j - 1][k][0]);
d[i][j][k][1] += abs(rg[j] - i - j - k);
}
if (i != 0) {
d[i][j][k][0] = min(d[i - 1][j][k][1] , d[i - 1][j][k][2]);
d[i][j][k][0] += abs(rp[i] - i - j - k);
}
//cout<<i<<" "<<j<<" "<<k<<'\n';
//cout<<d[i][j][k][0]<<" "<<d[i][j][k][1]<<" "<<d[i][j][k][2]<<'\n';
//cout<<'\n';
}
ll mn = min( {d[r][g][y][1], d[r][g][y][0], d[r][g][y][2]});
if (mn != INT_MAX)cout<<mn / 2;
else cout<<-1;
}
컴파일 시 표준 에러 (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... |