79242024-01-12 07:19:11szabelrSzínezéscpp17Időlimit túllépés 20/50699ms5540 KiB
// Színezés.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
using namespace std;
long long tomb[200001];
long long jok[200001];
int main()
{
    long long n, q,hol=1,db=0,dbmax,z,dbog=1,hany=2;
    string x;
    cin >> n >> q;
    cin >> x;
    for (int i = 1; i <= n; i++) {
        if (x[i-1] == '0') {
            tomb[i] = 0;
        }
        else
            tomb[i] = 1;
    }
    //0-ra
    while (hol <= n)
    {
        if (tomb[hol] == 1) {
            while (tomb[hol] == 1)
            {
                hol++;
            }
            db++;
        }
        if (tomb[hol] == 0) {
            hol++;
        }
    }
    dbmax = db;
    db = 0;
    hol = 1;
    //1re
    while (hol <= n)
    {
        if (tomb[hol] == 0) {
            while (tomb[hol] == 0)
            {
                hol++;
            }
            db++;
        }
        if (tomb[hol] == 1) {
            hol++;
        }
    }
    if (db < dbmax)
        dbmax = db;
    jok[1] = dbmax;

    for (int i = 1; i <= q; i++) {
        cin >> z;
        if (tomb[z] == 1)
            tomb[z] = 0;
        else
            tomb[z] = 1;
        db = 0;
        hol = 1;
        dbmax = 0;
        //0-ra
        while (hol <= n)
        {
            if (tomb[hol] == 1) {
                while (tomb[hol] == 1)
                {
                    hol++;
                }
                db++;
            }
            if (tomb[hol] == 0) {
                hol++;
            }
        }
        dbmax = db;
        db = 0;
        //cout << "0-ra" << dbmax << "i= " << i << endl;
        //1re
        hol = 1;
        while (hol <= n)
        {
            if (tomb[hol] == 0) {
                while (tomb[hol] == 0)
                {
                    hol++;
                }
                db++;
            }
            if (tomb[hol] == 1) {
                hol++;
            }
        }
        //cout << "1-re" << db << "i= " << i << endl;
        if (db < dbmax)
            dbmax = db;
        jok[hany] = dbmax;
        hany++;
    }
    for (int i = 1; i <= q + 1; i++) {
        cout << jok[i]<<endl;
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base20/50
1Elfogadva0/03ms1692 KiB
2Elfogadva0/0209ms2096 KiB
3Elfogadva2/23ms2372 KiB
4Elfogadva2/24ms2464 KiB
5Elfogadva3/34ms2620 KiB
6Elfogadva3/34ms2508 KiB
7Elfogadva3/3104ms2648 KiB
8Elfogadva3/328ms2996 KiB
9Elfogadva2/29ms3072 KiB
10Elfogadva2/212ms3444 KiB
11Időlimit túllépés0/3699ms4360 KiB
12Időlimit túllépés0/3679ms4628 KiB
13Időlimit túllépés0/3647ms4836 KiB
14Időlimit túllépés0/3653ms4792 KiB
15Időlimit túllépés0/3699ms4924 KiB
16Időlimit túllépés0/3643ms4864 KiB
17Időlimit túllépés0/3671ms5136 KiB
18Időlimit túllépés0/3666ms5072 KiB
19Időlimit túllépés0/3652ms5312 KiB
20Időlimit túllépés0/3699ms5540 KiB