답안 #122987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122987 2019-06-29T22:35:01 Z zoooma13 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
10 ms 7032 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 65
#define INF 0x3f3f3f3f

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

int to_rch[3][MAX_N][MAX_N][MAX_N];
int dp[3][MAX_N][MAX_N][MAX_N] ,root = -1;
int solve(int t ,int p0 ,int p1 ,int p2){
    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()){
			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);
		}
		
		memset(to_rch ,0 ,sizeof to_rch);
		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 i = p0+p1+p2 ,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] += 
				upper_bound(pos[h].begin()+st[h] ,pos[h].end() ,pos[t][st[t]])-(pos[h].begin()+st[h]);
		}

		memset(dp ,-1 ,sizeof dp);
		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:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p0=0; p0<=pos[0].size(); p0++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p1=0; p1<=pos[1].size(); p1++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int p2=0; p2<=pos[2].size(); p2++)
                 ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:56: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:55:8: warning: unused variable 'i' [-Wunused-variable]
    int i = p0+p1+p2 ,st[] = {p0 ,p1 ,p2};
        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6776 KB Output is correct
2 Correct 7 ms 6776 KB Output is correct
3 Correct 7 ms 6776 KB Output is correct
4 Correct 7 ms 6776 KB Output is correct
5 Correct 7 ms 6776 KB Output is correct
6 Correct 7 ms 6776 KB Output is correct
7 Correct 7 ms 6780 KB Output is correct
8 Correct 7 ms 6776 KB Output is correct
9 Correct 7 ms 6776 KB Output is correct
10 Correct 7 ms 6776 KB Output is correct
11 Correct 7 ms 6776 KB Output is correct
12 Correct 7 ms 6776 KB Output is correct
13 Correct 7 ms 6776 KB Output is correct
14 Correct 7 ms 6776 KB Output is correct
15 Correct 7 ms 6776 KB Output is correct
16 Correct 7 ms 6776 KB Output is correct
17 Correct 7 ms 6776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6776 KB Output is correct
2 Correct 7 ms 6776 KB Output is correct
3 Correct 7 ms 6776 KB Output is correct
4 Correct 7 ms 6776 KB Output is correct
5 Correct 7 ms 6776 KB Output is correct
6 Correct 7 ms 6776 KB Output is correct
7 Correct 7 ms 6780 KB Output is correct
8 Correct 7 ms 6776 KB Output is correct
9 Correct 7 ms 6776 KB Output is correct
10 Correct 7 ms 6776 KB Output is correct
11 Correct 7 ms 6776 KB Output is correct
12 Correct 7 ms 6776 KB Output is correct
13 Correct 7 ms 6776 KB Output is correct
14 Correct 7 ms 6776 KB Output is correct
15 Correct 7 ms 6776 KB Output is correct
16 Correct 7 ms 6776 KB Output is correct
17 Correct 7 ms 6776 KB Output is correct
18 Correct 8 ms 6776 KB Output is correct
19 Correct 8 ms 6776 KB Output is correct
20 Correct 8 ms 6776 KB Output is correct
21 Correct 8 ms 6776 KB Output is correct
22 Correct 8 ms 6776 KB Output is correct
23 Correct 8 ms 6776 KB Output is correct
24 Correct 8 ms 6776 KB Output is correct
25 Correct 7 ms 6776 KB Output is correct
26 Correct 8 ms 6776 KB Output is correct
27 Correct 8 ms 6776 KB Output is correct
28 Correct 8 ms 6776 KB Output is correct
29 Correct 8 ms 6776 KB Output is correct
30 Correct 9 ms 6776 KB Output is correct
31 Correct 9 ms 6776 KB Output is correct
32 Correct 8 ms 6776 KB Output is correct
33 Correct 7 ms 6776 KB Output is correct
34 Correct 7 ms 6776 KB Output is correct
35 Correct 8 ms 6748 KB Output is correct
36 Correct 8 ms 6776 KB Output is correct
37 Correct 8 ms 6776 KB Output is correct
38 Correct 8 ms 6776 KB Output is correct
39 Correct 8 ms 6776 KB Output is correct
40 Correct 7 ms 6776 KB Output is correct
41 Correct 7 ms 6776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6776 KB Output is correct
2 Runtime error 10 ms 7032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6776 KB Output is correct
2 Correct 7 ms 6776 KB Output is correct
3 Correct 7 ms 6776 KB Output is correct
4 Correct 7 ms 6776 KB Output is correct
5 Correct 7 ms 6776 KB Output is correct
6 Correct 7 ms 6776 KB Output is correct
7 Correct 7 ms 6780 KB Output is correct
8 Correct 7 ms 6776 KB Output is correct
9 Correct 7 ms 6776 KB Output is correct
10 Correct 7 ms 6776 KB Output is correct
11 Correct 7 ms 6776 KB Output is correct
12 Correct 7 ms 6776 KB Output is correct
13 Correct 7 ms 6776 KB Output is correct
14 Correct 7 ms 6776 KB Output is correct
15 Correct 7 ms 6776 KB Output is correct
16 Correct 7 ms 6776 KB Output is correct
17 Correct 7 ms 6776 KB Output is correct
18 Correct 8 ms 6776 KB Output is correct
19 Correct 8 ms 6776 KB Output is correct
20 Correct 8 ms 6776 KB Output is correct
21 Correct 8 ms 6776 KB Output is correct
22 Correct 8 ms 6776 KB Output is correct
23 Correct 8 ms 6776 KB Output is correct
24 Correct 8 ms 6776 KB Output is correct
25 Correct 7 ms 6776 KB Output is correct
26 Correct 8 ms 6776 KB Output is correct
27 Correct 8 ms 6776 KB Output is correct
28 Correct 8 ms 6776 KB Output is correct
29 Correct 8 ms 6776 KB Output is correct
30 Correct 9 ms 6776 KB Output is correct
31 Correct 9 ms 6776 KB Output is correct
32 Correct 8 ms 6776 KB Output is correct
33 Correct 7 ms 6776 KB Output is correct
34 Correct 7 ms 6776 KB Output is correct
35 Correct 8 ms 6748 KB Output is correct
36 Correct 8 ms 6776 KB Output is correct
37 Correct 8 ms 6776 KB Output is correct
38 Correct 8 ms 6776 KB Output is correct
39 Correct 8 ms 6776 KB Output is correct
40 Correct 7 ms 6776 KB Output is correct
41 Correct 7 ms 6776 KB Output is correct
42 Correct 7 ms 6776 KB Output is correct
43 Runtime error 10 ms 7032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Halted 0 ms 0 KB -