Submission #720997

# Submission time Handle Problem Language Result Execution time Memory
720997 2023-04-10T02:25:44 Z pcc Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
1 ms 224 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++)ans2 += 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++)ans2 += 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 0 ms 224 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 0 ms 224 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 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 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 0 ms 224 KB Output isn't correct
4 Halted 0 ms 0 KB -