Submission #720996

# Submission time Handle Problem Language Result Execution time Memory
720996 2023-04-10T02:23:18 Z pcc Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	string s;
	cin>>n>>s;
	int cnt[2] = {};
	for(int i = 0;i<n;i++){
		if(s[i] == 'R')cnt[0]++;
		else cnt[1]++;
	}
	if(abs(cnt[0]-cnt[1])>1){
		cout<<-1;
		return 0;
	}
	if(n&1){
		vector<int> pos;
		int ans = 0;
		for(int i = 0;i<n;i++){
			if(cnt[s[i] != 'R']>cnt[!(s[i] != 'R')])pos.push_back(i);
		}
		for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-i*2);
		cout<<ans;
	}
	else{
		vector<int> pos;
		int ans = 0;
		for(int i =0;i<n;i++){
			if(s[i] == 'R')pos.push_back(i);
		}
		for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-i*2);
		int ans2 = 0;
		for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-(i*2+1));
		cout<<min(ans,ans2);
	}
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-i*2);
      |                 ~^~~~~~~~~~~
joi2019_ho_t3.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-i*2);
      |                 ~^~~~~~~~~~~
joi2019_ho_t3.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0;i<pos.size();i++)ans += abs(pos[i]-(i*2+1));
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -