답안 #163519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163519 2019-11-13T17:30:31 Z nvmdava Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 163140 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 405
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
 
char c[N];
int dp[N][N][N][3];
int a[N];
vector<int> app[3];
 
int i[3];
 
int cost(int k, int r){
	i[k]--;
	int res = dp[i[0]][i[1]][i[2]][r];
	int v = app[k][i[k]];
	i[k]++;
	int w = v;
	for(int j = 0; j < 3; j++){
		int a = upper_bound(app[j].begin(), app[j].end(), v) - app[j].begin();
		w += max(0, i[j] - a);
	}
 
 
	return res + abs(i[0] + i[1] + i[2] - w);
}

int s[3];
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int n;
    cin>>n;
 
    for(int i = 1; i <= n; i++){
    	cin>>c[i];
    	if(c[i] == 'R')
    		app[0].push_back(i);
    	else if(c[i] == 'G')
    		app[1].push_back(i);
    	else
    		app[2].push_back(i);
    }

    for(int i = 0; i < 3; ++i)
    	s[i] = app[i].size();

    for(i[0] = 0; i[0] <= s[0]; ++i[0]){
    	for(i[1] = 0; i[1] <= s[1]; ++i[1]){
    		for(i[2] = 0; i[2] <= s[2]; ++i[2]){
    			for(int k = 0; k < 3; ++k){
    				dp[i[0]][i[1]][i[2]][k] = INF;

    				if(i[0] + i[1] + i[2] == 0)
    					dp[i[0]][i[1]][i[2]][k] = 0;
    				
    				if(i[k] == 0) continue;

    				for(int r = 0; r < 3; ++r){
    					if(k == r)
    						continue;
    					dp[i[0]][i[1]][i[2]][k] = min(dp[i[0]][i[1]][i[2]][k], cost(k, r));
    				}
    			}
    		}
    	}
    }
    int res = min(dp[s[0]][s[1]][s[2]][0], min(dp[s[0]][s[1]][s[2]][1], dp[s[0]][s[1]][s[2]][2]));
    if(res == 0x3f3f3f3f)
    	cout<<-1;
    else
    	cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 2 ms 508 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 2 ms 508 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 6 ms 2424 KB Output is correct
19 Correct 6 ms 1912 KB Output is correct
20 Correct 7 ms 2296 KB Output is correct
21 Correct 6 ms 2424 KB Output is correct
22 Correct 5 ms 1656 KB Output is correct
23 Correct 6 ms 2168 KB Output is correct
24 Correct 5 ms 1656 KB Output is correct
25 Correct 6 ms 3976 KB Output is correct
26 Correct 6 ms 4216 KB Output is correct
27 Correct 6 ms 3192 KB Output is correct
28 Correct 6 ms 2424 KB Output is correct
29 Correct 6 ms 2296 KB Output is correct
30 Correct 6 ms 2296 KB Output is correct
31 Correct 6 ms 2040 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 6 ms 3832 KB Output is correct
34 Correct 6 ms 3576 KB Output is correct
35 Correct 15 ms 2780 KB Output is correct
36 Correct 5 ms 1912 KB Output is correct
37 Correct 5 ms 1784 KB Output is correct
38 Correct 6 ms 2168 KB Output is correct
39 Correct 6 ms 2296 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 4 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 130 ms 163064 KB Output is correct
3 Correct 130 ms 162216 KB Output is correct
4 Correct 130 ms 163060 KB Output is correct
5 Correct 132 ms 163064 KB Output is correct
6 Correct 131 ms 163036 KB Output is correct
7 Correct 131 ms 162268 KB Output is correct
8 Correct 130 ms 162296 KB Output is correct
9 Correct 131 ms 161448 KB Output is correct
10 Correct 134 ms 163064 KB Output is correct
11 Correct 131 ms 163064 KB Output is correct
12 Correct 36 ms 44024 KB Output is correct
13 Correct 64 ms 77148 KB Output is correct
14 Correct 95 ms 111408 KB Output is correct
15 Correct 131 ms 163036 KB Output is correct
16 Correct 132 ms 163140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 2 ms 508 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 508 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 6 ms 2424 KB Output is correct
19 Correct 6 ms 1912 KB Output is correct
20 Correct 7 ms 2296 KB Output is correct
21 Correct 6 ms 2424 KB Output is correct
22 Correct 5 ms 1656 KB Output is correct
23 Correct 6 ms 2168 KB Output is correct
24 Correct 5 ms 1656 KB Output is correct
25 Correct 6 ms 3976 KB Output is correct
26 Correct 6 ms 4216 KB Output is correct
27 Correct 6 ms 3192 KB Output is correct
28 Correct 6 ms 2424 KB Output is correct
29 Correct 6 ms 2296 KB Output is correct
30 Correct 6 ms 2296 KB Output is correct
31 Correct 6 ms 2040 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 6 ms 3832 KB Output is correct
34 Correct 6 ms 3576 KB Output is correct
35 Correct 15 ms 2780 KB Output is correct
36 Correct 5 ms 1912 KB Output is correct
37 Correct 5 ms 1784 KB Output is correct
38 Correct 6 ms 2168 KB Output is correct
39 Correct 6 ms 2296 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 4 ms 2296 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 130 ms 163064 KB Output is correct
44 Correct 130 ms 162216 KB Output is correct
45 Correct 130 ms 163060 KB Output is correct
46 Correct 132 ms 163064 KB Output is correct
47 Correct 131 ms 163036 KB Output is correct
48 Correct 131 ms 162268 KB Output is correct
49 Correct 130 ms 162296 KB Output is correct
50 Correct 131 ms 161448 KB Output is correct
51 Correct 134 ms 163064 KB Output is correct
52 Correct 131 ms 163064 KB Output is correct
53 Correct 36 ms 44024 KB Output is correct
54 Correct 64 ms 77148 KB Output is correct
55 Correct 95 ms 111408 KB Output is correct
56 Correct 131 ms 163036 KB Output is correct
57 Correct 132 ms 163140 KB Output is correct
58 Execution timed out 1048 ms 76388 KB Time limit exceeded
59 Halted 0 ms 0 KB -