76132024-01-10 09:07:04AblablablaTakaros Sorozat (80 pont)cpp17Wrong answer 46/809ms8216 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<int> szamok(n + 1, 0);
    for(int i = 1; i <= n; i++){
        szamok[i] = s[i - 1] - '0';
    }

    vector<int> pref1(n + 1, 0);
    vector<int> suf1(n + 1, 0);
    for(int i = 1; i <= n; i++){
        pref1[i] = pref1[i - 1] + szamok[i];
    }

    for(int i = n - 1; i >= 0; i--){
        suf1[i] = suf1[i + 1] + (szamok[i + 1] == 0);
    }

    vector<int> pref2(n + 1, 0);
    vector<int> suf2(n + 1, 0);

    int nullas = 0;
    int egyes = 0;

    for(int i = 1; i <= n; i++){
        if(szamok[i]){
            egyes++;
        } else{
            nullas++;
        }

        if(i - 4 >= 1){
            if(szamok[i - 4]){
                egyes--;
            } else{
                nullas--;
            }
        }

        pref2[i] = pref2[i - 1] + (szamok[i]);

        if(nullas == 2 && egyes == 2){
            pref2[i] = min(pref2[i], pref2[i - 4] + 1);
        }
    }

    nullas = 0;
    egyes = 0;

    for(int i = n - 1; i >= 0; i--){
        if(szamok[i + 1]){
            egyes++;
        } else{
            nullas++;
        }

        if(i + 5 <= n){
            if(szamok[i + 5]){
                egyes--;
            } else{
                nullas--;
            }
        }

        suf2[i] = suf2[i + 1] + (szamok[i + 1] == 0);
        //cout << i << " : " << suf2[i] << " ";

        if(nullas == 2 && egyes == 2){
            suf2[i] = min(suf2[i], suf2[i + 4] + 1);
            //cout << suf2[i + 4] + 1;
        }
        //cout << "\n";
    }

    int mini = 2e9 + 7;
    for(int i = 0; i < n; i++){
        mini = min(mini, pref1[i] + suf1[i]);
    }
    cout << mini << "\n";
    for(int i = 0; i < n; i++){
        mini = min(mini, pref2[i] + suf2[i]);
    }

    cout << mini << "\n";
}
SubtaskSumTestVerdictTimeMemory
base46/80
1Accepted0/03ms1816 KiB
2Wrong answer0/09ms6136 KiB
3Wrong answer0/43ms2288 KiB
4Accepted4/43ms2492 KiB
5Partially correct2/43ms2700 KiB
6Partially correct2/43ms2904 KiB
7Partially correct2/43ms2896 KiB
8Accepted4/43ms3024 KiB
9Accepted4/43ms3108 KiB
10Wrong answer0/43ms3104 KiB
11Accepted4/43ms3388 KiB
12Wrong answer0/43ms3256 KiB
13Accepted4/48ms7080 KiB
14Partially correct2/48ms7336 KiB
15Accepted4/48ms7584 KiB
16Accepted4/48ms7644 KiB
17Partially correct2/48ms7624 KiB
18Wrong answer0/48ms7776 KiB
19Partially correct2/48ms8012 KiB
20Partially correct2/48ms8112 KiB
21Partially correct2/48ms8216 KiB
22Partially correct2/49ms8080 KiB