# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122653 | zoooma13 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 5 ms | 3580 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 65
#define INF 0x3f3f3f3f
int n;
string s;
vector <int> pos[3];
int dp[3][MAX_N][MAX_N][MAX_N] ,root = -1;
int solve(int t ,int p0=0 ,int p1=0 ,int p2=0){
int i = p0+p1+p2;
if(i == n)
return 0;
int&ret = (~t ? dp[t][p0][p1][p2] : root);
if(~ret)
return ret;
ret = INF;
int st[] = {p0 ,p1 ,p2};
for(int nt=0; nt<3; nt++)
if(t != nt && st[nt] < pos[nt].size()){
st[nt]++;
ret = min(ret ,max(pos[nt][st[nt]-1]-i ,0)+solve(nt ,st[0] ,st[1] ,st[2]));
st[nt]--;
}
return ret;
}
int main()
{
cin >> n;
cin >> s; n = s.size();
for(int i=0; i<n; i++){
if(s[i] == 'R') pos[0].push_back(i);
if(s[i] == 'G') pos[1].push_back(i);
if(s[i] == 'Y') pos[2].push_back(i);
}
memset(dp ,-1 ,sizeof dp);
solve(-1);
cout << (root == INF ? -1 : root) << endl;
}
Compilation message (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... |