Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
695 B
3
Indexable
#include <bits/stdc++.h>

using namespace std;

int n, res, cnt, idx; string s;
vector<int> v;

int main() // SAI
{
    freopen("PCHAR.INP","r",stdin);
    freopen("PCHAR.OUT","w",stdout);

    cin >> n >> s; cnt = idx = 0;
    s = s + 'x';
    for(int i = 1; i <= n; i++){
        if(s[i] != s[i-1]){
            cnt = i - idx;
            v.push_back(cnt);
            idx = i;
        }
    }
    if(s[0] == '.') v.erase(v.begin());
    if(s[n-1] == '#'){
        n = v.size();
        v.erase(v.begin() + n - 1);
    }
    n = v.size();

    res = cnt = 0;
    for(int i = 1; i < n; i+=2) cnt += v[i];
    for(int i = 0; i < n; i+=2) res += v[i];
    cout << min(res, cnt);

    return 0;
}
Leave a Comment