CSES - Datatähti 2019 loppu - Results
Submission details
Task:Bittijono
Sender:Olli Järviniemi
Submission time:2019-01-17 12:20:12 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED21
#2ACCEPTED27
#3ACCEPTED52
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1details
#2ACCEPTED0.03 s1details
#3ACCEPTED0.02 s1details
#4ACCEPTED0.02 s1details
#5ACCEPTED0.02 s1details
#6ACCEPTED0.03 s1details
#7ACCEPTED0.01 s1details
#8ACCEPTED0.02 s2details
#9ACCEPTED0.02 s2details
#10ACCEPTED0.02 s2details
#11ACCEPTED0.02 s2details
#12ACCEPTED0.01 s2details
#13ACCEPTED0.02 s2details
#14ACCEPTED0.02 s2details
#15ACCEPTED0.05 s3details
#16ACCEPTED0.05 s3details
#17ACCEPTED0.04 s3details
#18ACCEPTED0.04 s3details
#19ACCEPTED0.05 s3details
#20ACCEPTED0.03 s3details
#21ACCEPTED0.02 s3details

Code

#include <iostream>

using namespace std;

const int N = 5e5 + 5;

typedef long long ll;

ll o[N]; //amount of ones <= i
ll even[N]; //amount of indexes <= i with o[j] even
ll odd[N]; //amount of indexes <= i with o[j] odd



int main() {
    string s;
    cin >> s;
    int n = s.length();
    
    if(s[0] == '1') {
        o[1] = 1;
        odd[1] = 1;
    } else {
        even[1] = 1;
    }
    for(int i = 2; i <= n; ++i) {
        if(s[i-1] == '0') {
            o[i] = o[i-1];
        } else {
            o[i] = o[i-1] + 1;
        }
        
        if(o[i]%2 == 0) {
            even[i] = even[i-1] + 1;
            odd[i] = odd[i-1];
        } else {
            even[i] = even[i-1];
            odd[i] = odd[i-1] + 1;
        }
    }
    
    ll ans = 0;
    for(int i = 1; i <= n; ++i) {
        if(o[i]%2 == 1) {
            ans += (ll) odd[i] - 1;
        } else {
            ans += (ll) even[i];
        }
    }
    
    cout << ans << "\n";
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
2500

user output
2500

Test 2

Group: 1

Verdict: ACCEPTED

input
111101111111101111111011011110...

correct output
2502

user output
2502

Test 3

Group: 1

Verdict: ACCEPTED

input
000110011101101000000000101010...

correct output
2590

user output
2590

Test 4

Group: 1

Verdict: ACCEPTED

input
110101000010001000101100011000...

correct output
2502

user output
2502

Test 5

Group: 1

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
5050

user output
5050

Test 6

Group: 1

Verdict: ACCEPTED

input
0

correct output
1

user output
1

Test 7

Group: 1

Verdict: ACCEPTED

input
1

correct output
0

user output
0

Test 8

Group: 2

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
6250000

user output
6250000

Test 9

Group: 2

Verdict: ACCEPTED

input
111111111110101111111010111011...

correct output
6250342

user output
6250342

Test 10

Group: 2

Verdict: ACCEPTED

input
110110111000000001011100000011...

correct output
6252352

user output
6252352

Test 11

Group: 2

Verdict: ACCEPTED

input
000000001000101001001110100011...

correct output
6253422

user output
6253422

Test 12

Group: 2

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
12502500

user output
12502500

Test 13

Group: 2

Verdict: ACCEPTED

input
0

correct output
1

user output
1

Test 14

Group: 2

Verdict: ACCEPTED

input
1

correct output
0

user output
0

Test 15

Group: 3

Verdict: ACCEPTED

input
111111111111111111111111111111...

correct output
62500000000

user output
62500000000

Test 16

Group: 3

Verdict: ACCEPTED

input
101101100110111101111011111101...

correct output
62500057360

user output
62500057360

Test 17

Group: 3

Verdict: ACCEPTED

input
011100000010000011110101010001...

correct output
62500117306

user output
62500117306

Test 18

Group: 3

Verdict: ACCEPTED

input
001010011010000001100011001101...

correct output
62500144780

user output
62500144780

Test 19

Group: 3

Verdict: ACCEPTED

input
000000000000000000000000000000...

correct output
125000250000

user output
125000250000

Test 20

Group: 3

Verdict: ACCEPTED

input
0

correct output
1

user output
1

Test 21

Group: 3

Verdict: ACCEPTED

input
1

correct output
0

user output
0