Submission #883021

#TimeUsernameProblemLanguageResultExecution timeMemory
883021vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++11
15 / 100
1 ms756 KiB
#include <bits/stdc++.h> #define pb push_back #define endl ("\n") #define all(aa) aa.begin(), aa.end() typedef long long ll; using namespace std; int solve(int target, vector<int> v){ int ret = 0; for(int i = 0; i < v.size(); i++){ target ^=1; if(v[i] == target) continue; int j; for(j = 1; i+j < v.size(); j++){ if(v[i+j] == target){ v[i+j]^=1; break; } } ret+=j; } return ret; } int main(){ int n, cnt = 0; cin >> n; vector<int> v(n); for(int i = 0; i < n; i++){ char c; cin >> c; v[i] = (c=='R'); cnt += v[i]; } if(cnt > (n+1)/2 || (n-cnt) > (n+1)/2){ cout << -1; exit(0); } if(n > 2*cnt){ for(int i = 0; i < n; i++) v[i] ^=1; cnt = n - cnt; } int ans = solve(0, v); if(!(n&1)) ans = min(ans, solve(1, v)); cout << ans << endl; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int solve(int, std::vector<int>)':
joi2019_ho_t3.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
joi2019_ho_t3.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(j = 1; i+j < v.size(); j++){
      |              ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...