Editorial for Bedao Mini Contest 02 - BSTRING


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Code mẫu

#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include <bitset>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <assert.h>

#define _(x) (1LL<<(x))
#define BIT(x,pos) (((x)>>(pos)) & 1LL)
#define turn_all(x) (_(x)-1LL)
#define bitCnt(x) __builtin_popcountll(x)

#define name "test"
#define nameTask ""
#define fastIO ios::sync_with_stdio(false); cin.tie(0);

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int N = 1E6;
const int INF = 2E9;

int n;
int p[N+9];
string s;

int main()
{
    fastIO

    cin>>n;
    cin>>s;
    s = ' ' + s;

    int cnt0 = 0;
    for (int i = 1;i <= n; ++i)
    {
        p[i] = p[i-1] + (s[i] == '1');
        cnt0 += (s[i] == '0');
    }

    int res = min(p[cnt0]-p[0], p[n] - p[n-cnt0]);

    cout<<res;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.