답안 #701384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701384 2023-02-21T06:30:30 Z Baytoro Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
63 ms 163048 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
//#define int long long
#define ll long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+7;
const int N=405;
vector<int> r,g,y;
int p[N][3],dp[N][N][N][3];
void solve(){
	int n;cin>>n;
	string s;cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R') r.pb(i+1);
		if(s[i]=='G') g.pb(i+1);
		if(s[i]=='Y') y.pb(i+1);
		p[i+1][0]=r.size();
		p[i+1][1]=g.size();
		p[i+1][2]=y.size();
	}
	for(int i=0;i<=(int)r.size();i++){
		for(int j=0;j<=(int)g.size();j++){
			for(int k=0;k<=(int)y.size();k++){
				if(!i && !j && !k) continue;
				for(int l=0;l<3;l++) dp[i][j][k][l]=mod;
				int sum=i+j+k;
				if(i) dp[i][j][k][0]=min(dp[i-1][j][k][1],dp[i-1][j][k][2])+((r[i-1]+max(0,j-p[r[i-1]][1])+max(0,k-p[r[i-1]][2]))-sum);
				if(j) dp[i][j][k][1]=min(dp[i][j-1][k][0],dp[i][j-1][k][2])+((g[j-1]+max(0,i-p[g[j-1]][0])+max(0,k-p[g[j-1]][2]))-sum);
				if(k) dp[i][j][k][2]=min(dp[i][j][k-1][0],dp[i][j][k-1][1])+((y[k-1]+max(0,i-p[y[k-1]][0])+max(0,j-p[y[k-1]][1]))-sum);
			}
		}
	}
	int ans=*min_element(dp[r.size()][g.size()][y.size()],dp[r.size()][g.size()][y.size()]+3);
	if(ans>=mod) ans=-1;
	cout<<ans;
}
main(){
	ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

joi2019_ho_t3.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
joi2019_ho_t3.cpp: In function 'void fopn(std::string)':
joi2019_ho_t3.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 1 ms 2388 KB Output is correct
22 Correct 1 ms 1620 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 1 ms 1624 KB Output is correct
25 Correct 2 ms 3924 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 1 ms 3028 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 1 ms 2260 KB Output is correct
30 Correct 1 ms 2260 KB Output is correct
31 Correct 1 ms 2004 KB Output is correct
32 Correct 1 ms 2388 KB Output is correct
33 Correct 2 ms 3796 KB Output is correct
34 Correct 1 ms 3540 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 1876 KB Output is correct
37 Correct 1 ms 1740 KB Output is correct
38 Correct 1 ms 2132 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 57 ms 162964 KB Output is correct
3 Correct 55 ms 162124 KB Output is correct
4 Correct 54 ms 162896 KB Output is correct
5 Correct 58 ms 162916 KB Output is correct
6 Correct 57 ms 162868 KB Output is correct
7 Correct 60 ms 162084 KB Output is correct
8 Correct 55 ms 162128 KB Output is correct
9 Correct 55 ms 161340 KB Output is correct
10 Correct 55 ms 162984 KB Output is correct
11 Correct 56 ms 162952 KB Output is correct
12 Correct 16 ms 43988 KB Output is correct
13 Correct 27 ms 77064 KB Output is correct
14 Correct 40 ms 111356 KB Output is correct
15 Correct 57 ms 163048 KB Output is correct
16 Correct 54 ms 162856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 2260 KB Output is correct
21 Correct 1 ms 2388 KB Output is correct
22 Correct 1 ms 1620 KB Output is correct
23 Correct 1 ms 2132 KB Output is correct
24 Correct 1 ms 1624 KB Output is correct
25 Correct 2 ms 3924 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 1 ms 3028 KB Output is correct
28 Correct 1 ms 2260 KB Output is correct
29 Correct 1 ms 2260 KB Output is correct
30 Correct 1 ms 2260 KB Output is correct
31 Correct 1 ms 2004 KB Output is correct
32 Correct 1 ms 2388 KB Output is correct
33 Correct 2 ms 3796 KB Output is correct
34 Correct 1 ms 3540 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 1876 KB Output is correct
37 Correct 1 ms 1740 KB Output is correct
38 Correct 1 ms 2132 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 2132 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 57 ms 162964 KB Output is correct
44 Correct 55 ms 162124 KB Output is correct
45 Correct 54 ms 162896 KB Output is correct
46 Correct 58 ms 162916 KB Output is correct
47 Correct 57 ms 162868 KB Output is correct
48 Correct 60 ms 162084 KB Output is correct
49 Correct 55 ms 162128 KB Output is correct
50 Correct 55 ms 161340 KB Output is correct
51 Correct 55 ms 162984 KB Output is correct
52 Correct 56 ms 162952 KB Output is correct
53 Correct 16 ms 43988 KB Output is correct
54 Correct 27 ms 77064 KB Output is correct
55 Correct 40 ms 111356 KB Output is correct
56 Correct 57 ms 163048 KB Output is correct
57 Correct 54 ms 162856 KB Output is correct
58 Correct 46 ms 76220 KB Output is correct
59 Correct 52 ms 96548 KB Output is correct
60 Correct 51 ms 87780 KB Output is correct
61 Correct 50 ms 84812 KB Output is correct
62 Correct 57 ms 160592 KB Output is correct
63 Correct 58 ms 160144 KB Output is correct
64 Correct 61 ms 150080 KB Output is correct
65 Correct 63 ms 138448 KB Output is correct
66 Correct 52 ms 86040 KB Output is correct
67 Correct 47 ms 82984 KB Output is correct
68 Correct 49 ms 88604 KB Output is correct
69 Correct 49 ms 85452 KB Output is correct
70 Correct 50 ms 92500 KB Output is correct
71 Correct 47 ms 83916 KB Output is correct
72 Correct 20 ms 41532 KB Output is correct
73 Correct 2 ms 2900 KB Output is correct