# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
670309 | dozer | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 534 ms | 1040460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define endl "\n"
#define sp " "
#define N 405
int dp[N][N][N][4];
vector<int> r, g, y;
int n;
const int INF = 1e9 + 7;
int f(int i, int j, int k, int last)
{
int t1 = INF, t2 = INF, t3 = INF;
int pos = i + j + k + 1;
if (pos > n) return 0;
if (dp[i][j][k][last] != -1) return dp[i][j][k][last];
if (i < r.size() && last != 0) t1 = f(i + 1, j, k, 0) + abs(r[i] - pos);
if (j < g.size() && last != 1) t2 = f(i, j + 1, k, 1) + abs(g[j] - pos);
if (k < y.size() && last != 2) t3 = f(i, j, k + 1, 2) + abs(y[k] - pos);
int res = min(t1, t2);
res = min(res, t3);
return dp[i][j][k][last] = res;
}
int32_t main()
{
fastio();
memset(dp, -1, sizeof(dp));
cin>>n;
for (int i = 1; i <= n; i++)
{
char tmp;
cin>>tmp;
if (tmp == 'R') r.pb(i);
else if (tmp == 'Y') y.pb(i);
else g.pb(i);
}
int ans = f(0, 0, 0, 3);
if (ans >= INF) cout<<-1<<endl;
else cout<<ans / 2<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
컴파일 시 표준 에러 (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... |