CSES - HIIT Open 2018 - Results
Submission details
Task:Inversions
Sender:Tefyn virallinen maajoukkue
Submission time:2018-05-26 11:16:16
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.06 sdetails

Code

#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int d1 = 0, d2 = 0;
    for(int i = 0; i < n; ++i){
        if(i%2 == 0){
            if(s[i] == '0')
                d1++;
            else
                d2++;
            
        }
        else {
         if(s[i] == '0')
                d2++;
            else
                d1++;
            
            
        }
        
    }
    cout << min(d1, d2) << endl;
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
500000

user output
500000

Test 2

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
500000

user output
500000

Test 3

Verdict: ACCEPTED

input
010101010101010101010101010101...

correct output
0

user output
0

Test 4

Verdict: ACCEPTED

input
101010101010101010101010101010...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
110101011010110100100111110110...

correct output
499476

user output
499476