Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:23:07
Task:Inversions
Sender:Wave of Technology
Submission time:2018-05-26 11:23:07
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <vector>

using namespace std;

typedef long long ll;




int main() {

  string s;
  cin >> s;

  vector<bool> b;
  for (auto c : s) {
    b.push_back(c=='1');
  }

  int n = b.size();
  
  ll codd = 0;
  ll ceven = 0;
  for (int i=0; i<n; i++) {
    codd += b[i]^(i&1);
    ceven += !(b[i]^(i&1));
  }
  
  cout << min(codd, ceven) << endl;
}