답안 #199065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199065 2020-01-29T04:02:44 Z mahmoudbadawy Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
13 ms 6776 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> pos[3];
int mem[404][404][404][3];
int vis[404][404][404][3];
int n;
string s;

int go(int x,int y,int z,int las)
{
	if(x+y+z==n) return 0;
	int &ret=mem[x][y][z][las];
	if(vis[x][y][z][las]) return ret;
	vis[x][y][z][las]=1;
	ret=(1<<30);
	int cpos=x+y+z;
	if(x<pos[0].size()&&(las!=0||cpos==0))
		ret=min(ret,go(x+1,y,z,0)+abs(cpos-pos[0][x]));
	if(y<pos[1].size()&&(las!=1||cpos==0))
		ret=min(ret,go(x,y+1,z,1)+abs(cpos-pos[1][y]));
	if(z<pos[2].size()&&(las!=2||cpos==0))
		ret=min(ret,go(x,y,z+1,2)+abs(cpos-pos[2][z]));
	return ret;
}

int main()
{
	cin >> n >> s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R') pos[0].push_back(i);
		else if(s[i]=='G') pos[1].push_back(i);
		else pos[2].push_back(i);
	}
	int ans=go(0,0,0,0);
	if(ans>=(1<<30)) ans=-1;
	else ans/=2;
	cout << ans << endl;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int go(int, int, int, int)':
joi2019_ho_t3.cpp:19:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(x<pos[0].size()&&(las!=0||cpos==0))
     ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:21:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(y<pos[1].size()&&(las!=1||cpos==0))
     ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:23:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(z<pos[2].size()&&(las!=2||cpos==0))
     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Incorrect 5 ms 760 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Incorrect 5 ms 760 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 13 ms 6648 KB Output is correct
3 Correct 11 ms 6648 KB Output is correct
4 Correct 11 ms 6776 KB Output is correct
5 Correct 11 ms 6652 KB Output is correct
6 Correct 11 ms 6648 KB Output is correct
7 Correct 10 ms 6648 KB Output is correct
8 Correct 10 ms 6648 KB Output is correct
9 Correct 9 ms 6648 KB Output is correct
10 Correct 9 ms 6648 KB Output is correct
11 Correct 10 ms 6648 KB Output is correct
12 Correct 7 ms 3576 KB Output is correct
13 Correct 8 ms 4728 KB Output is correct
14 Correct 9 ms 5496 KB Output is correct
15 Correct 10 ms 6664 KB Output is correct
16 Correct 10 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Incorrect 5 ms 760 KB Output isn't correct
12 Halted 0 ms 0 KB -