Problem:


Score : 300 points

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.
A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.

Constraints

1 \leq N \leq 2\times 10^5

S is a string of length N consisting of . and #.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of stones that needs to be recolored.

Sample Input 1

3
#.#

Sample Output 1

1

It is enough to change the color of the first stone to white.

Sample Input 2

5
#.##.

Sample Output 2

2

Sample Input 3

9
.........

Sample Output 3

0



Sample input:
3
#.#


Sample output:
1

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = input()

sa = np.array([1 if i == "#" else 0 for i in S])
num = np.arange(N)
num_w = num[sa==0]
num_b = num[sa==1]
if len(num_w) == 0 or len(num_b) == 0:
    print(0)
    import sys
    sys.exit()
if num_b[-1] == N-1:
    w0 = 0
    w = len(num_w)
    b = np.sum([num_b<num_w[-1]])
else:
    w = np.sum([num_w<num_b[-1]])
    w0 = len(num_w) - w
    b = np.sum([num_b<num_w[num_w<num_b[-1]][-1]])
if w > b:
    print(b+w0)
else:
    print(w+w0)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <map>
#include <cstdlib>
#define INF (1000000007)
#define rep(i,N) for(ll i=0;i<N;i++)
#define rep2(i,j,k) for(ll i=j; i<k;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using vs=vector<string>;
using vvs=vector<vector<string>>;

template <typename T>
void print(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": "<<v[i]<<endl;}
}

template <typename T>
void print2(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": ";
        for(size_t j=0;j<v[0].size();j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
}

template <typename T>
T slice(T v,ll left,ll right){
    T ret(0);
    copy(v.begin()+left,v.begin()+right,back_inserter(ret));
    return ret;
}

int main(){
    ll N;
    string S;
    cin>>N>>S;
    ll ans=0;

    if(S[0]=='#' && S[1]=='.'){
        ans+=1;
    }

    rep2(i,1,N-2){
        if(S[i]=='#' && S[i+1]=='.'){
            ans+=1;
            if(S[i-1]=='#' && S[i+1]=='#'){
                S[i+1]='#';
            }
        }
    }
            
    if(S[N-2]=='#' && S[N-1]=='.'){
        ans+=1;
    }

    cout<<ans<<endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
c = 0
for i in range(0,n) :
    if s[i] == '#' and s[i] == s[i+1] :
        c += 0
    elif s[i] == '#' and s[i] != s[i+1] :
        c += 1
    else :
        c += 0
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
s = np.array(list(input())) == '.'

index = np.where(s[::-1])[0][0]

if index == 0:
    check_list = s
else:
    check_list = s[:-index]

print(min(check_list.sum(), np.logical_not(check_list).sum()))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

r1 = 0
for i in range(len(s) - 1):
    if s[i] == '#' and s[i+1] == '.':
        s[i+1] = '#'
        r1 += 1

print(r1)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

cnt = 0
i = 0
while True:
    if s[i] == '.':
        break
    i += 1

if i == n:
    pass
else:
    for j in range(i, n):
        if s[j] == '#':
            cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

cand = [j for j in range(len(s)) if s[j] =="#" and s[j+1] !="#"]
count =0
if start == -1 or end == -1:
    print(0)
else:
    for i in cand:
        if s[i] == "#" and s[i+1] == ".":
            count +=1
    print(count)

Submission status: Runtime Error

Solution code:
#coding: utf-8
N = int(input())
S = list(input())
ans = 0
for j in range(i, N):
    if S[j] == ".":
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    # reverse
    S = S[::-1]
    # 白が現れるまで省く
    idx = S.index('.')
    S = S[idx:]
    # あとは少ない方を裏返せば良い
    print(min(S.count('.'), S.count('#')))


lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())

flag = 0
for i, s in enumerate(S):
    if s == '.' and flag:
        idx = i - 1
        break
    if s == '#':
        flag = 1
        
S = S[idx:]
num_black = S.count('#')
num_white = S.count('.')
print(min([num_black, num_white]))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
s=S.index('.')
k=S[s::]
a=k.count('.')
b=k.count('#')
if a>b: print(b)
else: print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
for i in range(N):
  if S[-i+1] == '.':
    M = S[:N-i]
    break
print(min(M.count('.'),M.count('#')))

Submission status: Runtime Error

Solution code:
a = int(input())
b = str(input())

for i in range(a):
    if b[i:i+2] == "#.":
        res = b[i:a].count(".")
        break
        
for i in range(a,-1,-1):
    if b[i:i+2] == "#.":
        res = min(b[0:i+2].count("#"),res)
        break

print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
S = str(input())

ans = 0
for i in range(N-1):
    if i == 0:
        check1 = S[i]
        check2 = S[i+1]
        check3 = S[i+2]
        if check1 == '#' and check2 == '.':
            ans += 1
    elif i == N-2:
        check1 = S[i]
        check2 = S[i+1]
        if check1 == '#' and check2 == '.':
            ans += 1
    else:
        check1 = S[i-1]
        check2 = S[i]
        check3 = S[i+1]
        check4 = S[i+2]
        if check1 == '.' and check2 == '#' and check3 == '.' and check4 == '#':
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())
# ".": 白
# "#": 黒
# 黒い石のすぐ右に白い石があるような箇所がないように
ans=0
for i in range(N-1):
    if S[i]=="#" and S[i+1]==".":
        S[i+1]="#"
        ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
sl=list(s)

res=0
for i in range(n):
	if sl[i]=="#" and sl[i+1]==".":
		res= res + 1
        
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())

count_1 = 0
count_2 = 0
for i in range(N-1):
  if S[i] == "#" and S[i+1] == ".":
    S[i+1] = "#"
    count_1 += 1
for i in range(N-1):
  if S[N - i] == "." and S[N - i - 1] == "#":
    S[N - i] = "#"
    count_2 += 1
    
print(min(count_1, count_2))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
li = []
for i in range(n):
    if s[i] == "#":
        li.append(i)
sum = 0
if len(li) == 0:
    print(0)
for i in range(len(li)-1):
    sum += li[i+1]-li[i]-1 
sum += len(s) - li[-1] - 1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()

def dfs(stones, start, count):
  if(N-1<=start): return count
  for i in range(start, N-1):
    if(stones[i]=="#" and stones[i+1]=="."):
      return min(dfs(stones[:i]+"."+stones[i+1:], start+1, count+1), dfs(stones[:i+1]+"#"+stones[i+2:], start+1,count+1))
  return count

print(dfs(S, 0, 0))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
siro = s.count(".")
ren = 0
i = 1
while s[-i] == "#":
    ren += 1
    i += 1
print(min(siro,n-ren-siro))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
count = 0

for i in range(N-1):
    if S[i:i+2] = '#.':
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
N=input()
s=input()
s=[s[i] for i in range(N)]
hit=0
count=0
for i in s:
    if i=="#":
        hit = 1
    if hit==1 and i==".":
        count=count+1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
for i in range(N-1):
    if S[i] == "." and S[i+1] == "#":
        break
sharp_count = 0
for j in range(i+1,N):
    if S[j] == "#":
        sharp_count += 1

print(sharp_count)

Submission status: Runtime Error

Solution code:
hit=0
count=0
for i in s:
    if i=="#":
        hit = 1
    if hit==1 and i==".":
        count=count+1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
i=0
c=0
for i in range (n):
    j=i+1
    if s[i]=='#' :
        if s[j]=='.':
            c+=1
          
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
a = np.empty(N)
for i in range(N):
        a[i] = int(input())


S2 = S.split("#")[1:]
if S2 == S:
        print("0")
else:
    sn = S2.count(".")
    sn2 = S.count("#")
    print(min(sn,sn2))

Submission status: Runtime Error

Solution code:
index = int(input())
s = input()

count = 0
for i in range(index - 1):
  if s[i] == '#' and s[i+1] == '.':
    count += 1
    
pritn(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

k = 0

for i, c in enumerate(s):
    if c == "#":
        if i != len(s) and s[i + 1] == ".":
            k += 1

print(k)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
print(S.counet("#."))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
s = list(s)
cnt = 0
for i in range(n):
  if s[i] == '#' and s[i+1] == '.':
    s[i+1] == '#'
    cnt+=1

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
if "." in s:
    a = [i for i, x in enumerate(s) if x == '.'][-1]
    ans1 = s[:a].count("#")
else:
    ans2 = 0
if "#" in s:
    b = [i for i, x in enumerate(s) if x == '#'][0]
    ans2 = s[b:].count(".")
else:
    ans2 = 0
print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
n = ip()                                     #入力整数1つ
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(3)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
p = 0
while a[p] == '.':p+=1
x,y = 0,0
for i in range(p,n):
    if a[i] == '#':x+=1
    else: y+=1
print(min(x,y))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()+'?'
white=s.count('.')
black=s.count('#')
ans1=n-black
ans2=n-white
index=s.index('.')
ans3=index+s[index+1:].count('.')
print(min(ans1,ans2,ans3))