Task: | Inversions |
Sender: | Wave of Technology |
Submission time: | 2018-05-26 11:23:07 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.07 s | details |
#3 | ACCEPTED | 0.05 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.06 s | details |
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; }
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 |