69842023-12-23 19:30:10MagyarKendeSZLGSzínezéscpp17Time limit exceeded 20/50699ms3900 KiB
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define speed cin.tie(0); ios::sync_with_stdio(0)

vector<bool> balls;
int N, Q;

void solve() {
    int z_sum = 0, o_sum = 0, i = 0;
    while (i < N) {
        if (balls[i]) o_sum++;
        else z_sum++;
        do {
            i++;
        } while (i < N && balls[i - 1] == balls[i]);
    }
    // cout << z_sum << ' ' << o_sum << ' ';
    cout << min(z_sum, o_sum) << '\n';
}

int main() {
    speed;
    string s;
    cin >> N >> Q >> s;
    balls.resize(N);
    for (int i = 0; i < N; i++) {
        balls[i] = s[i] == '1';
    }

    solve();
    while (Q--) {
        int i;
        cin >> i;
        balls[i - 1] = !balls[i - 1];
        solve();
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1828 KiB
2Accepted0/090ms2172 KiB
3Accepted2/23ms2236 KiB
4Accepted2/23ms2332 KiB
5Accepted3/33ms2692 KiB
6Accepted3/33ms2872 KiB
7Accepted3/37ms3092 KiB
8Accepted3/37ms3152 KiB
9Accepted2/27ms3292 KiB
10Accepted2/27ms3288 KiB
11Time limit exceeded0/3699ms3028 KiB
12Time limit exceeded0/3679ms3228 KiB
13Time limit exceeded0/3677ms3284 KiB
14Time limit exceeded0/3670ms3492 KiB
15Time limit exceeded0/3662ms3416 KiB
16Time limit exceeded0/3671ms3352 KiB
17Time limit exceeded0/3675ms3488 KiB
18Time limit exceeded0/3675ms3900 KiB
19Time limit exceeded0/3699ms3840 KiB
20Time limit exceeded0/3649ms3872 KiB