답안 #922350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922350 2024-02-05T12:28:29 Z elotelo966 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
9 ms 18012 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY LLONG_MAX
#define mod 998244353
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 65
#define fi first
#define se second
int n;// 1 2 3
int cev=LLONG_MAX;
vector<int> v[4];
int dp[lim][lim][lim][4];

inline int dpp(int red,int gre,int yel,int sira,int renk,int tut){
	//cout<<red<<" "<<gre<<" "<<yel<<" "<<sira<<" "<<tut<<" "<<renk<<" "<<st+'Y'<<endl;
	if(red==v[1].size() && gre==v[2].size() && yel==v[3].size()){
		return tut;
	}
	if(~dp[red][gre][yel][renk])return dp[red][gre][yel][renk];
	int yum=LLONG_MAX;
	if(renk!=1 && red<v[1].size()){
		//cout<<"r"<<red<<" "<<gre<<" "<<yel<<" "<<sira<<" "<<tut<<" "<<abs(v[1][red]-sira)<<" "<<st+'R'<<endl;
		yum=min(yum,dpp(red+1,gre,yel,sira+1,1,tut+abs(v[1][red]-sira)));
	}
	if(renk!=2 && gre<v[2].size()){
		//cout<<"g"<<red<<" "<<gre<<" "<<yel<<" "<<sira<<" "<<tut<<" "<<abs(v[2][gre]-sira)<<" "<<st+'G'<<endl;
		yum=min(yum,dpp(red,gre+1,yel,sira+1,2,tut+abs(v[2][gre]-sira)));	
	}
	if(renk!=3 && yel<v[3].size()){
		//cout<<"y"<<red<<" "<<gre<<" "<<yel<<" "<<sira<<" "<<tut<<" "<<abs(v[3][yel]-sira)<<" "<<st+'Y'<<endl;
		yum=min(yum,dpp(red,gre,yel+1,sira+1,3,tut+abs(v[3][yel]-sira)));
	}
	return dp[red][gre][yel][renk]=yum;
}

int32_t main(){
	faster
	memset(dp,-1,sizeof(dp));
	cin>>n;
	string s;cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R')v[1].push_back(i+1);
		else if(s[i]=='G')v[2].push_back(i+1);
		else v[3].push_back(i+1);
	}
	string h="";
	int deg=dpp(0,0,0,1,0,0);
	if(deg==LLONG_MAX)deg=-2;
	cout<<deg/2<<'\n';
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'long long int dpp(long long int, long long int, long long int, long long int, long long int, long long int)':
joi2019_ho_t3.cpp:18:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if(red==v[1].size() && gre==v[2].size() && yel==v[3].size()){
      |     ~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:18:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if(red==v[1].size() && gre==v[2].size() && yel==v[3].size()){
      |                         ~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:18:48: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if(red==v[1].size() && gre==v[2].size() && yel==v[3].size()){
      |                                             ~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:23:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  if(renk!=1 && red<v[1].size()){
      |                ~~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:27:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  if(renk!=2 && gre<v[2].size()){
      |                ~~~^~~~~~~~~~~~
joi2019_ho_t3.cpp:31:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  if(renk!=3 && yel<v[3].size()){
      |                ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Incorrect 2 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Incorrect 2 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 9 ms 18012 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Incorrect 2 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -