제출 #110402

#제출 시각아이디문제언어결과실행 시간메모리
110402pamajGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
60 ms384 KiB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 410;

int n;

bool check(vector<pair<char, int>> &t)
{
	for(int i = 0; i < t.size() - 1; i++)
		if(t[i].first == t[i + 1].first) return false;

	return true;
}

int main()
{
	cin >> n;
	
	vector<pair<char, int>> s, t;

	for(int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		s.push_back({c, i});
	}

	t = s;

	sort(s.begin(), s.end());

	int ans = 1e9;

	do
	{
		if(check(s))
		{
			int num_dif = 0;

			for(int i = 0; i < n; i++)
				if(s[i].second != t[i].second) num_dif++;

			ans = min(ans, num_dif);
		} 
	} while(next_permutation(s.begin(), s.end()));

	cout << (ans == (int)1e9 ? -1 : ans) << "\n";

}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t3.cpp: In function 'bool check(std::vector<std::pair<char, int> >&)':
joi2019_ho_t3.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < t.size() - 1; i++)
                 ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...