| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 99752 | MrTEK | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 148 ms | 163064 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const int N = 4e2 + 5;
const int INF = 1e9;
int n,f[3],mpx[300],dp[N][N][N][3];
char s[N];
vector <pair <int,ii>> pos[3];
inline int calc(pair <int,ii> x,pair <int,ii> y) {
return abs(x.first - y.first) + abs(x.second.first - y.second.first) + abs(x.second.second - y.second.second);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
mpx['R'] = 0;
mpx['G'] = 1;
mpx['Y'] = 2;
cin >> n >> (s + 1);
for (int i = 1 ; i <= n ; i++) {
f[mpx[s[i]]]++;
pos[mpx[s[i]]].push_back({f[0],{f[1],f[2]}});
}
for (int r = 0 ; r <= f[0] ; r++) {
for (int g = 0 ; g <= f[1] ; g++) {
for (int y = 0 ; y <= f[2] ; y++) {
if (r + g + y == 0)
continue;
for (int i = 0 ; i < 3 ; i++)
dp[r][g][y][i] = INF;
if (r > 0)
dp[r][g][y][0] = min(dp[r - 1][g][y][1],dp[r - 1][g][y][2]) + calc(pos[0][r - 1],{r,{g,y}});
if (g > 0)
dp[r][g][y][1] = min(dp[r][g - 1][y][0],dp[r][g - 1][y][2]) + calc(pos[1][g - 1],{r,{g,y}});
if (y > 0)
dp[r][g][y][2] = min(dp[r][g][y - 1][0],dp[r][g][y - 1][1]) + calc(pos[2][y - 1],{r,{g,y}});
}
}
}
int ans = INF;
for (int i = 0 ; i < 3 ; i++)
ans = min(ans,dp[f[0]][f[1]][f[2]][i]);
if (ans == INF)
cout << "-1" << endl;
else
cout << ans / 2 << endl;
}컴파일 시 표준 에러 (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... | ||||
