76262024-01-10 09:27:55AblablablaTakaros Sorozat (80 pont)cpp17Wrong answer 64/8012ms9892 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);
    }

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

    vector<int> elotte(n + 1, 0);
    vector<int> utana(n + 2, 0);
    for(int i = 1; i <= n; i++){
        if(szamok[i]){
            elotte[i] = i;
        } else{
            elotte[i] = elotte[i - 1];
        }
    }

    for(int i = n; i >= 1; i--){
        if(!szamok[i]){
            utana[i] = i;
        } else{
            utana[i] = utana[i + 1];
        }
    }

    vector<int> dpe(n + 2, 0);
    vector<int> dpu(n + 2, 0);
    for(int i = 1; i <= n; i++){
        dpe[i] = dpe[i - 1];
        if(szamok[i] && elotte[i - 1]){
            if(abs(elotte[i - 1] - i) <= 3){
                dpe[i] = dpe[elotte[i - 1] - 1] + 1;
            } else{
                dpe[i] = dpe[elotte[i - 1]] + 1;
            }
        } else if(szamok[i]){
            dpe[i] = 1;
        }
    }

    for(int i = n; i >= 1; i--){
        dpu[i] = dpu[i + 1];
        if(!szamok[i] && utana[i + 1]){
            if(abs(utana[i + 1] - i) <= 3){
                dpu[i] = dpu[utana[i + 1] + 1] + 1;
            } else{
                dpu[i] = dpu[utana[i + 1]] + 1;
            }
        } else if(!szamok[i]){
            dpu[i] = 1;
        }
    }

    for(int i = 0; i < n; i++){
        mini = min(mini, dpe[i] + dpu[i + 1]);
    }

    cout << mini << "\n";
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1944 KiB
2Accepted0/012ms7900 KiB
3Wrong answer0/43ms2476 KiB
4Accepted4/43ms2564 KiB
5Partially correct2/43ms2776 KiB
6Accepted4/43ms2896 KiB
7Accepted4/43ms3148 KiB
8Accepted4/43ms3136 KiB
9Accepted4/43ms3248 KiB
10Wrong answer0/42ms3332 KiB
11Accepted4/43ms3460 KiB
12Partially correct2/42ms3548 KiB
13Accepted4/48ms9180 KiB
14Accepted4/48ms9140 KiB
15Accepted4/48ms9780 KiB
16Accepted4/48ms9684 KiB
17Accepted4/48ms9616 KiB
18Wrong answer0/48ms9744 KiB
19Accepted4/48ms9616 KiB
20Accepted4/49ms9892 KiB
21Accepted4/49ms9728 KiB
22Accepted4/410ms9852 KiB