Submission #122990

# Submission time Handle Problem Language Result Execution time Memory
122990 2019-06-29T22:58:19 Z zoooma13 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 402
#define INF 0x3f3f3f3f

int n;
string s;
vector <int> pos[3];

int root = -1;
int smlr[3][MAX_N][MAX_N];
vector<vector<vector<int>>> dp[3] ,to_rch[3];
int solve(int t ,int p0 ,int p1 ,int p2){
    if(p0+p1+p2 == 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()){
			int cost = to_rch[nt][st[0]][st[1]][st[2]];
			st[nt]++;
            ret = min(ret ,cost+solve(nt ,st[0] ,st[1] ,st[2]));
            st[nt]--;
        }
    return ret;
}

int main()
{
	freopen("input.in" ,"r" ,stdin);
	
	while(cin >> n){
		pos[0].clear();
		pos[1].clear();
		pos[2].clear();
		
		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);
		}
		
		for(int i=0; i<3; i++){
			dp[i].clear() ,to_rch[i].clear();
			dp[i].resize(pos[0].size()+1 ,vector<vector<int>>(pos[1].size()+1 ,vector<int>(pos[2].size()+1 ,-1)));
			to_rch[i].resize(pos[0].size()+1 ,vector<vector<int>>(pos[1].size()+1 ,vector<int>(pos[2].size()+1 ,0)));
		}
		
		for(int t=0; t<3; t++)
		for(int i=0; i<pos[t].size(); i++){
			int pt_ptr = i;
			for(int j=0; j<n; j++){
				while(pt_ptr < pos[t].size() && pos[t][pt_ptr] <= j)
					pt_ptr++;
				smlr[t][i][j] = pt_ptr-i;
			}
		}
		
		for(int p0=0; p0<=pos[0].size(); p0++)
		for(int p1=0; p1<=pos[1].size(); p1++)
		for(int p2=0; p2<=pos[2].size(); p2++)
		{
			int st[] = {p0 ,p1 ,p2};
			for(int t=0; t<3; t++) if(st[t] < pos[t].size())
			for(int h=0; h<3; h++) if(h != t)
				to_rch[t][p0][p1][p2] += smlr[h][st[h]][pos[t][st[t]]];
		}

		root = -1 ,solve(-1 ,0 ,0 ,0);
		cout << (root == INF ? -1 : root) << endl;
	}
}

Compilation message

joi2019_ho_t3.cpp: In function 'int solve(int, int, int, int)':
joi2019_ho_t3.cpp:24:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(t != nt && st[nt] < pos[nt].size()){
                       ~~~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:57:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<pos[t].size(); i++){
                ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:60:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(pt_ptr < pos[t].size() && pos[t][pt_ptr] <= j)
           ~~~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p0=0; p0<=pos[0].size(); p0++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p1=0; p1<=pos[1].size(); p1++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p2=0; p2<=pos[2].size(); p2++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:71:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int t=0; t<3; t++) if(st[t] < pos[t].size())
                              ~~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.in" ,"r" ,stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -