답안 #122654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122654 2019-06-29T03:14:39 Z zoooma13 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
4 ms 3576 KB
#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){
		assert(p0 == pos[0].size() && p1 == pos[1].size() && p2 == pos[2].size());
        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] < (int)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()
{
	//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(dp ,-1 ,sizeof dp);
		root = -1 ,solve(-1);
		cout << (root == INF ? -1 : root) << endl;
	}
}

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from joi2019_ho_t3.cpp:1:
joi2019_ho_t3.cpp: In function 'int solve(int, int, int, int)':
joi2019_ho_t3.cpp:15:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(p0 == pos[0].size() && p1 == pos[1].size() && p2 == pos[2].size());
          ~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:15:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(p0 == pos[0].size() && p1 == pos[1].size() && p2 == pos[2].size());
                                 ~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:15:59: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(p0 == pos[0].size() && p1 == pos[1].size() && p2 == pos[2].size());
                                                        ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3576 KB Output is correct
2 Correct 4 ms 3576 KB Output is correct
3 Correct 4 ms 3576 KB Output is correct
4 Correct 4 ms 3576 KB Output is correct
5 Correct 4 ms 3576 KB Output is correct
6 Correct 4 ms 3576 KB Output is correct
7 Correct 4 ms 3576 KB Output is correct
8 Correct 4 ms 3576 KB Output is correct
9 Correct 4 ms 3576 KB Output is correct
10 Correct 4 ms 3576 KB Output is correct
11 Incorrect 4 ms 3576 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3576 KB Output is correct
2 Correct 4 ms 3576 KB Output is correct
3 Correct 4 ms 3576 KB Output is correct
4 Correct 4 ms 3576 KB Output is correct
5 Correct 4 ms 3576 KB Output is correct
6 Correct 4 ms 3576 KB Output is correct
7 Correct 4 ms 3576 KB Output is correct
8 Correct 4 ms 3576 KB Output is correct
9 Correct 4 ms 3576 KB Output is correct
10 Correct 4 ms 3576 KB Output is correct
11 Incorrect 4 ms 3576 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3576 KB Output is correct
2 Incorrect 4 ms 3576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3576 KB Output is correct
2 Correct 4 ms 3576 KB Output is correct
3 Correct 4 ms 3576 KB Output is correct
4 Correct 4 ms 3576 KB Output is correct
5 Correct 4 ms 3576 KB Output is correct
6 Correct 4 ms 3576 KB Output is correct
7 Correct 4 ms 3576 KB Output is correct
8 Correct 4 ms 3576 KB Output is correct
9 Correct 4 ms 3576 KB Output is correct
10 Correct 4 ms 3576 KB Output is correct
11 Incorrect 4 ms 3576 KB Output isn't correct
12 Halted 0 ms 0 KB -