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:14:03
Task:Inversions
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:14:03
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:8:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<s.size();++i){
                  ~^~~~~~~~~

Code

#include <iostream>
using namespace std;
string s;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> s;
    int a=0;int b=0;
    for (int i=0;i<s.size();++i){
        a+=(s[i]=='1')==(i&1);
        b+=(s[i]=='1')!=(i&1);
    }
    cout << min(a, b) << "\n";
}