Submission #720996

#TimeUsernameProblemLanguageResultExecution timeMemory
720996pccGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
1 ms212 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...