답안 #884480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884480 2023-12-07T13:24:20 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 86424 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
const int INF=1e8;

int n;
vector<int> ind[3];
map<pair<array<int, 3>, char>, int> dp;

int f(array<int, 3> x, char l){
	if(x[0]+x[1]+x[2]==n) return 0;
	if(dp.count({x, l})) return dp[{x, l}]; 

	int minn=INF;
	for(int i=0; i<3; i++) if(i!=l && x[i]!=ind[i].size()){
		int o=0, s=x[0]+x[1]+x[2];
		for(int j=0; j<3; j++) if(j!=i)
			o+=max(0, (int)(ind[j].begin()+x[j]-upper_bound(all(ind[j]), ind[i][x[i]])));

		x[i]++;
		minn=min(minn, f(x, i)+o+ind[i][x[i]-1]-s);
		x[i]--;
	}
	return dp[{x, l}]=minn;
}

int main(){
	string s;
	cin>>n>>s;

	for(int i=0; i<n; i++){
		if(s[i]=='R')
			ind[0].push_back(i);
		else if(s[i]=='G')
			ind[1].push_back(i);
		else
			ind[2].push_back(i);
	}

	int ans=f(array<int, 3>{0, 0, 0}, 3);
	cout<<(ans>=INF ? -1:ans)<<endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int f(std::array<int, 3>, char)':
joi2019_ho_t3.cpp:18:40: warning: comparison of integer expressions of different signedness: 'std::array<int, 3>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0; i<3; i++) if(i!=l && x[i]!=ind[i].size()){
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 8 ms 1116 KB Output is correct
19 Correct 8 ms 1196 KB Output is correct
20 Correct 8 ms 1116 KB Output is correct
21 Correct 8 ms 1116 KB Output is correct
22 Correct 5 ms 860 KB Output is correct
23 Correct 8 ms 1116 KB Output is correct
24 Correct 5 ms 860 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 5 ms 860 KB Output is correct
28 Correct 8 ms 1148 KB Output is correct
29 Correct 10 ms 1116 KB Output is correct
30 Correct 8 ms 1260 KB Output is correct
31 Correct 8 ms 1112 KB Output is correct
32 Correct 8 ms 1192 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 6 ms 860 KB Output is correct
36 Correct 8 ms 1136 KB Output is correct
37 Correct 6 ms 860 KB Output is correct
38 Correct 6 ms 932 KB Output is correct
39 Correct 8 ms 1112 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 8 ms 1116 KB Output is correct
19 Correct 8 ms 1196 KB Output is correct
20 Correct 8 ms 1116 KB Output is correct
21 Correct 8 ms 1116 KB Output is correct
22 Correct 5 ms 860 KB Output is correct
23 Correct 8 ms 1116 KB Output is correct
24 Correct 5 ms 860 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 5 ms 860 KB Output is correct
28 Correct 8 ms 1148 KB Output is correct
29 Correct 10 ms 1116 KB Output is correct
30 Correct 8 ms 1260 KB Output is correct
31 Correct 8 ms 1112 KB Output is correct
32 Correct 8 ms 1192 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 6 ms 860 KB Output is correct
36 Correct 8 ms 1136 KB Output is correct
37 Correct 6 ms 860 KB Output is correct
38 Correct 6 ms 932 KB Output is correct
39 Correct 8 ms 1112 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 508 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Execution timed out 1084 ms 86424 KB Time limit exceeded
59 Halted 0 ms 0 KB -