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: Wrong Answer

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

w_cnt = stones.count('.')
b_cnt = N-w_cnt
first_bi = max(0, stones.find('#'))
last_wi = max(0, stones.rfind('.'))
pw_cnt = stones[first_bi:].count('.')
pb_cnt = stones[:last_wi].count('#')

print(min(w_cnt, b_cnt, pw_cnt, pb_cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
init = True
for i in range(n):
    if (not init) and s[i] == '#':
        ans -= 1
    if init and s[i] == '#':
        ans = n - i - 1
        init = False
cnt = 0
for c in s[::-1]:
    if c == '.':
        break
    cnt += 1
ans = min(ans, s.count('#') - cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
init = True
for i in range(n):
    if (not init) and s[i] == '#':
        ans -= 1
    if init and s[i] == '#':
        ans = n - i - 1
        init = False
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()+'.'
tmp=s.count('.')-1
ans=tmp
for i in range(n):
  if s[i+1]=='.':
    tmp-=1
  if s[i]=='#':
    tmp+=1
  ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:

def resolve():
    N = int(input())
    S = input()

    pre = ""
    cnt = 0
    for s in S:
        if pre == "#":
            if s == ".":
                cnt += 1
                pre = "#"
                continue
        else:
            pre = s

    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(input())

    if S.count("#")==0:
        print(0)
        exit()
    a=S.index("#")

    white = S[a:].count(".")

    black = S.count("#")


    for i in range(N-1,-1,-1):
        if S[i]=="#":
            black -=1
        else:
            break


    print(min(black,white))





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(input())

    if S.count("#")==0:
        print(0)
        exit()
    a=S.index("#")

    white = S[a:].count(".")

    black = S.count("#")
    print(min(black,white))





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cw = 0
cb = 0
flag = False
a = -1
b = 0
for i in range(n):
    if s[i] == ".":
        cw += 1
    else:
        if flag == False:
            a = i
            flag = True
        cb += 1
if s[-1] == "#":
    b = 1
print(min(min(cb-b,cw),cw-a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cw = 0
cb = 0
flag = False
a = -1
b = 0
for i in range(n):
    if s[i] == ".":
        cw += 1
    else:
        if flag == False:
            a = i
            flag = True
        cb += 1
if s[-1] == ".":
    b = 1
print(min(min(cb,cw),cw-a))

Submission status: Wrong Answer

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

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

if n == 1:
    print(0)
else:
    ans = []
    for i in range(n+1):
        ans.append(black[i-1]+white[-1]-white[i-1])
    print(min(ans))

Submission status: Wrong Answer

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

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

if n == 1:
    print(0)
else:
    ans = []
    for i in range(n):
        ans.append(black[i-1]+white[-1]-white[i-1])
    print(min(ans))

Submission status: Wrong Answer

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

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

if n == 1:
    print(0)
else:
    ans = []
    for i in range(1,n):
        ans.append(black[i-1]+white[-1]-white[i-1])
    print(min(ans))

Submission status: Wrong Answer

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

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

if n == 1:
    print(0)
else:
    ans = []
    for i in range(1,len(s)):
        ans.append(black[i-1]+white[-1]-white[i])
    print(min(ans))

Submission status: Wrong Answer

Solution code:

N=int(input())
S=input()


lst = [0]

c1 = S.count(".")
c2 = S.count("#")

if c1<=c2:
    for i in range(N):
        if S[i:i+2]=="#.":
            lst.append(lst[i]+1)
            S=S[:i+1]+"#"+S[i+2:]
        else:
            lst.append(lst[i])
    print(lst[-1])
else:
    for i in range(N-1,-1,-1):
        if S[i:i+2]=="#.":
            lst.append(lst[N-1-i]+1)
            S=S[:i]+"."+S[i+1:]
        else:
            lst.append(lst[N-1-i])

    print(max(lst))

Submission status: Wrong Answer

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

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

ans = []
for i in range(len(s)):
    ans.append(min(white[i],black[-1]-black[i]))

print(min(ans))

Submission status: Wrong Answer

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


lst = [0]
for i in range(N):
    if S[i:i+2]=="#.":
        lst.append(lst[i]+1)
        S=S[:i+1]+"#"+S[i+2:]
    else:
        lst.append(lst[i])
print(lst[-1])

Submission status: Wrong Answer

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

flg = False
countw = 0
countb = 0
tmpb = 0
for l in s:
    if l=="#":
        flg = True
        tmpb+=1
    else:
        if flg:
            countw+=1
            countb+=tmpb
            tmpb=0

print(min(countw,countb))

Submission status: Wrong Answer

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

flg = False
countw = 0
countb = 0
for l in s:
    if l=="#":
        flg = True
        countb+=1
    else:
        if flg:
            countw+=1

print(min(countw,countb))

Submission status: Wrong Answer

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

flg = False
countw = 0
countb = 0
for l in s:
    if l=="#":
        flg = True
        countb+=1
    else:
        if flg:
            countw+=1

print(max(countw,countb))

Submission status: Wrong Answer

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

flg = False
count = 0
for l in s:
    if l=="#":
        flg = True
    else:
        if flg:
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
num = 0
for i in range(N):
  if S[i - 1] == '#' and S[i] ==".":
    num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import math
from datetime import date

def main():

	n = int(input())
	s = input()
	s1 = 0
	s2 = 0
	for x in s:
		if x == '.':
			s1 += 1
		else:
			s2 += 1

	print(min(s1, s2))

main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline
N = int(input())
S = list(input().strip())
counter = Counter(S)
if len(counter) == 1:
    print(0)
else:
    print(min(counter["."], counter["#"]))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
S = list(input().strip())
S = S[::-1]

ans = 0
for i in range(N-2):
    if S[i] == ".":
        if S[i+1] == "." and S[i+2] == "#":
            S[i+2] = "."
            ans += 1
        if S[i+1] == "#":
            ans += 1
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == "#":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
S = list(input().strip())
S = S[::-1]

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
S = list(input().strip())

ans = 0
for i in range(N-2):
    if S[i] == "#" and S[i+1] == ".":
        if S[i+2] == "#":
            S[i+1] = "#"
        else:
            S[i] = "."
        ans += 1
    if S[i] == "#" and S[i+1] == "#" and S[i+2] == ".":
        S[i+2] = "#"
        ans += 1
print(ans)

Submission status: Wrong Answer

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

# 左側の黒の個数, 右側の白の個数
ans = n
b, w = 0, s.count('.')
for i in range(n):
    if s[i] == '#':
        b += 1
    elif s[i] == '.':
        w -= 1
    ans = min(ans, b+w)
print(ans)

Submission status: Wrong Answer

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

# 最右の白より左側の黒を白に変える
c1 = s[:s.rfind('.')].count('#')

# 最左の黒より右側の白を黒に変える
c2 = s[s.find('#'):].count('.')

print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
m = 10 ** 6
tot1 = 0
cnt1 = 0
cnt0 = 0
for s in S:
    if(s == '#'):
        cnt0 += 1
    else:
        cnt1 += 1
        tot1 += 1
    m = min(m,cnt0-cnt1)
m += tot1
if(cnt0 == len(S)):
    m = 0
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
m = 10 ** 6
tot1 = 0
cnt1 = 0
cnt0 = 0
for s in S:
    if(s == '#'):
        cnt0 += 1
    else:
        cnt1 += 1
        tot1 += 1
    m = min(m,cnt0-cnt1)
m += tot1
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if '#' in set(S):
    SF = S.index('#')
    print(S[SF:].count('.'))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
print(input().count('#.'))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=s.count('.')
cnt=ans

for i in s:
    if i=='.':
        cnt+=1
    
    else:
        cnt-=1
        ans=min(ans,cnt)

ans=min(ans,cnt)


print(ans)

Submission status: Wrong Answer

Solution code:
from copy import *
n = int(input())
s = list(input())
S = []
l = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        S.append(s[l:i+1])
        l = i+1
if len(S) == 0:
    print(0)
else:
    if S[-1][0] == s[-1]:
        S[-1] += s[l:]
    else:
        S.append(s[l:])
    
    
    ans = 0
    m = len(S)
    
    if S[0][0] == '#':
        for i in range(m//2):
            ans += min(len(S[i*2]), len(S[i*2+1]))
    else:
        for i in range(m//2 - 1):
            ans += min(len(S[i*2+1]), len(S[i*2+2]))
    
    print(ans)

Submission status: Wrong Answer

Solution code:
from copy import *
n = int(input())
s = list(input())
t = deepcopy(s)
cnt1 = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt1 += 1
        s[i+1] = '#'

cnt2 = 0
for i in range(n-1):
    if t[i] == '#' and t[i+1] == '.':
        cnt2 += 1
        t[i+1] = '.'


print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  S = input()
  black = S.count('#')
  white = S.count('.')

  if black == 0 or white == 0:
    print(0)
    return 
 	
  B = [0]*(N+1)
  W = [0]*(N+1)
  for i in range(N):
    if S[i] == '#':
      B[i+1] = 1
    elif S[i] == '.':
      W[i+1] = 1
  
  for i in range(1,N+1):
    B[i]+=B[i-1]
    W[i]+=W[i-1]
  ans = float('inf')
  for i in range(1,N+1):
    ans = min(ans, B[i]+white-W[i])
  
  print(ans)
  return
main()

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  S = input()
  black = S.count('#')
  white = S.count('.')

  if black == N or white == N:
    print(0)
    return 
 	
  B = [0]*(N+1)
  W = [0]*(N+1)
  for i in range(N):
    if S[i] == '#':
      B[i+1] = 1
    elif S[i] == '.':
      W[i+1] = 1
  
  for i in range(1,N+1):
    B[i]+=B[i-1]
    W[i]+=W[i-1]
  ans = float('inf')
  for i in range(1,N+1):
    ans = min(ans, B[i]+white-W[i])
  
  print(ans)
  return
main()

Submission status: Wrong Answer

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)

x = 0
y = S.count('.')
c = min(n-y, y)
for i in range(n):
  t = S[i]=='#'
  x += t
  y -= t
  c = min(c, x+y)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
x, y = 0, S.count('.')
c = min(n, n-y)
for i in range(n):
  t = S[i]=='#'
  x += t
  y -= t
  c = min(c, x+y)
print(c)

Submission status: Wrong Answer

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

x, y, c = 0, S.count('.'), n
for i in range(n):
  t = S[i]=='#'
  x += t
  y -= t
  c = min(c, x+y)
print(c)

Submission status: Wrong Answer

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)
A = list(S)
ans = n
x = 0
y = S.count('.')
for i in range(n):
  if S[i] == '#':
    x += 1
  else:
    y -= 1
  ans = min(ans, x + y)
print(ans)

Submission status: Wrong Answer

Solution code:
_ = input()
S = input().lstrip('.').rstrip('#')
n = len(S)
x = 0
y = S.count('.')
ans = y
for i in range(n):
  if S[i] == '#':
    x += 1
    y -= 1
  ans = min(ans, x+n-i-1-y)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
S = S.lstrip('.').rstrip('#')
print(min(S.count('.'), S.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
S = S.lstrip('#')
print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
A = list(S)
B = list(S)
c0 = 0
for i in range(n-1):
  if A[i] + A[i+1] == '#.':
    c0 += 1
    A[i+1] = '#'
c1 = 0
for i in range(n-1):
  if B[i] + B[i+1] == '#.':
    c1 += 1
    B[i] = '.'
print(max(c0, c1))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=[]
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    ans.append(stones['b']+stones['w'])
if 'b' in stones:
    if stones['b']==N:
        print(0)
    else:
        print(min(ans))
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
print(s.count('#.'))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=[]
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    ans.append(stones['b']+stones['w'])
print(min(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N-1):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    if S[n]=='#' and S[n+1]=='.':
        ans+=min(stones['b'],stones['w'])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N-1):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    if S[n]!=S[n+1]:
        ans+=min(stones['b'],stones['w'])
print(min(ans,black,white))

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
s=input()
fw=False
fb=False
b=0
w=0
for i in range(n):
    if fb and s[i]==".":
        w+=1
    if fw and s[n-1-i]=="#":
        b+=1
    if not fb and s[i]=="#":
        fb=True
    if not fw and s[n-1-i]==".":
        fw=True
print(min(b,w))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
white = s.count('.')
ans, black = float('inf'), 0
for i in s:
    if i == '#':
        black += 1
    elif i == '.':
        white -= 1
    ans = min(ans, white+black)
print(ans)

Submission status: Wrong Answer

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

try:
    a = s.index('#')
    s = s[a:]
except:
    pass
ans, black, white = 0, 0, 0
for i in s[::-1]:
    if i == '.':
        white += 1
    elif i == '#' and white > 0:
        black += 1
        
print(min(white, black))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
bla=0
whi=0
for n in range(N-1):
    if S[n]=='.':
        white+=1
        whi+=1
    else:
        black+=1
        bla+=1
    if S[n]=='.' and S[n+1]=='#':
        ans+=min(white,black)
        white=0
        black=0
if S[-1]=='.':
    white+=1
else:
    black+=1
if S[-1]=='.':
    ans+=min(white,black)
    whi+=1
else:
    bla+=1
print(min(ans,whi,bla))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
bla=0
whi=0
for n in range(N-1):
    if S[n]=='.':
        white+=1
        whi+=1
    else:
        black+=1
        bla+=1
    if S[n]=='.' and S[n+1]=='#':
        ans+=min(white,black)
        white=0
        black=0
if S[-1]=='.':
    white+=1
else:
    black+=1
if S[-1]=='.':
    ans+=min(white,black)
print(min(ans,whi,bla))

Submission status: Wrong Answer

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

ans, black, white = 0, 0, 0
for i in s:
    if black > 0 and white > 0 and i == '#':
        if black < white:
            ans = black
        else:
            ans += min(black, white)
        black += 1
        white = 0
    elif i == '#':
        black += 1
    elif black > 0 and i == '.':
        white += 1
if black > 0 and white > 0:
    ans += min(black, white)
print(ans)

Submission status: Wrong Answer

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

ans, black, white = 0, 0, 0
for i in s:
    if black > 0 and white > 0 and i == '#':
        ans += min(black, white)
        black = 1
        white = 0
    elif i == '#':
        black += 1
    elif black > 0 and i == '.':
        white += 1
if black > 0 and white > 0:
    ans += min(black, white)
print(ans)

Submission status: Wrong Answer

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

ans, black, white = 0, 0, 0
for i in s:
    if black > 0 and white > 0 and i == '#':
        ans += min(black, white)
        black = 1
        white = 0
    elif i == '#':
        black += 1
    else:
        white += 1
if black > 0 and white > 0:
    ans += min(black, white)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
s0 = list(input())
s1 = copy.deepcopy(s0)
ans0, ans1 = 0, 0
for i in range(n-1, 0, -1):
    if s0[i] == '.' and s0[i-1] == '#':
        ans0 += 1
        s0[i] = '#'

for i in range(n-1, 0, -1):
    if s1[i] == '.' and s1[i-1] == '#':
        ans1 += 1
        s1[i-1] = '.'

print(min(ans0, ans1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(lambda x: 1 if x=="#" else 0,input()))

'''
"....####",".......","#########"のいずれかになればよい
累積和を左から見ていけば良い
'''
from itertools import accumulate
S = list(accumulate(S))

fills = min(N,S[-1],N-S[-1])

ans = fills

for i in range(N):
    _left = S[i]
    _right = N-i-(S[-1]-S[i])
    ans = min(ans,_left+_right)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(lambda x: 1 if x=="#" else 0,input()))

'''
"....####",".......","#########"のいずれかになればよい
累積和を左から見ていけば良い
'''
from itertools import accumulate
S = list(accumulate(S))

fills = min(N,S[-1],N-S[-1])

ans = fills

for i in range(N-1):
    _left = S[i]
    _right = N-i-(S[-1]-S[i])
    ans = min(ans,_left+_right)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(lambda x: 1 if x=="#" else 0,input()))

'''
"....####",".......","#########"のいずれかになればよい
累積和を左から見ていけば良い
'''
from itertools import accumulate
S = list(accumulate(S))

fills = min(N,S[-1],N-S[-1])

ans = fills

for i in range(N-1):
    _left = S[i]
    _right = N-i-(fills-S[i])
    ans = min(ans,_left+_right)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(lambda x: 1 if x=="#" else 0,input()))

'''
"....####",".......","#########"のいずれかになればよい
累積和を左から見ていけば良い
'''
from itertools import accumulate
S = list(accumulate(S))

fills = min(N,S[-1],N-S[-1])

ans = fills

for i in range(N-1):
    _left = S[i]
    _right = N-i-(fills-S[i])
    ans = min(fills,_left+_right)

print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
S=input()
ans=0
black=0
white=0
for n in range(N-1):
    if S[n]=='.':
        white+=1
    else:
        black+=1
    if S[n]=='.' and S[n+1]=='#':
        ans+=min(white,black)
        white=0
        black=0
if S[-1]=='.':
    white+=1
else:
    black+=1
if S[-1]=='.':
    ans+=min(white,black)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
if S[0]=='.':
    white+=1
else:
    black+=1
for n in range(N-1):
    if S[n+1]=='.':
        white+=1
    else:
        black+=1
    if S[n]=='.' and S[n+1]=='#':
        ans+=min(white,black)
        white=0
        black=1
ans+=min(white,black)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
black=0
white=0
if S[0]=='.':
    white+=1
else:
    black+=1
for n in range(N-1):
    if S[n+1]=='.':
        white+=1
    else:
        black+=1
    if S[n]=='#' and S[n+1]=='.':
        ans+=min(black,white)
        black=0
        white=0
    elif S[n]=='.' and S[n+1]=='.':
        black=0
    elif S[n]=='#' and S[n+1]=='#':
        white=0
    elif S[n]=='.' and S[n+1]=='#':
        white=0
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1e9)+7
INF = float('inf')


def solve():
    n = int(input())
    s = input()
    p = [0] * n
    r = [0] * n
    for i in range(n):
        if i: p[i] += p[i-1]
        if s[i] == '.': p[i] += 1
    for i in range(n-1,-1,-1):
        if i+1<n: r[i] += r[i+1]
        if s[i] == '#': r[i] += 1
    ans = min(p[-1], r[0])
    for i in range(n-1):
        left = (i + 1) - p[i]
        right = (n - i + 1) - r[i + 1]
        ans = min(ans, left + right)
    print(ans)
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
1
4
-1 1 1 -1

"""

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    black = s.count("#")
    ans, white = black, 0
    for i in range(n):
        if s[i] == ".":
            white += 1
        else:
            black -= 1
        tmp = n - black - white
        if tmp < ans:
            ans = tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    black = s.count("#")
    ans = 10**10
    cnt = 0
    for i in range(n):
        if s[i] == "#":
            cnt += 1
        tmp = n - black + 2*cnt - i - 1
        if tmp < ans:
            ans = tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
w=c.count(".")
b=n-w
#全部黒にする場合
ans1=w
#全部白にする場合
ans2=b
ans3=10**10
ans4=10**10
if w!=0 and b!=0:
    #一番左の黒より右をすべて黒にする
    for i in range(n):
        if c[i]=="#":
            l=i
            break
    ans3=c[l:].count(".")
    #一番右の白より左をすべて白にする
    for i in range(n):
        if c[-i-1]==".":
            r=(-i-1)
            break
    ans4=c[:n+r].count("#")
    #print(l,r)
#print(ans1,ans2,ans3,ans4)
print(min(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
w=c.count(".")
b=n-w
#全部黒にする場合
ans1=w
#全部白にする場合
ans2=b
ans3=10**10
ans4=10**10
if w!=0 and b!=0:
    #一番左の黒より右をすべて黒にする
    for i in range(n):
        if c[i]=="#":
            l=i
            break
    ans3=c[l:].count(".")
    #一番右の白より左をすべて白にする
    for i in range(n):
        if c[-i-1]==".":
            r=(-i-1)
            break
    ans4=c[:r].count("#")
    #print(l,r)
#print(ans1,ans2,ans3,ans4)
print(min(ans1,ans2,ans3,ans4))

Submission status: Wrong Answer

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

bcnt = S.count("#")
wcnt = N - bcnt

ans = float("inf")
cntb = 0
cntw = 0
for i in range(N):
    if S[i] == "#":
        cntb += 1
    else:
        cntw += 1

    ans = min(ans, cntb + wcnt - cntw)


print(ans)

Submission status: Wrong Answer

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

if S.count("#.") == 0:
    print(0)
    exit()

cnt = 0
for i in range(N):
    if S[-1 -i] == "#":
        cnt += 1
    else:
        break

for i in range(N):
    if S[i] == ".":
        continue

    print(min(S[i:].count("#") - cnt, S[i:].count(".")))
    exit()

print(0)

Submission status: Wrong Answer

Solution code:
def solve(s):
    found_black = False
    count_white = 0
    for c in s:
        if c == '#':
            found_black = True
        else:
            if found_black:
                count_white += 1
    found_white = False
    count_black = 0
    for c in reversed(s):
        if c == '.':
            found_white = True
        else:
            if found_white:
                count_black += 1
    
    s = s.lstrip('.')
    s = s.rstrip('#')
    answer = min(s.count('.'), s.count('#'))
    assert answer == min(count_white, count_black)
    return answer


def main():
    _ = int(input())
    s = input()
    print(solve(s))

if __name__ == "__main__":
    main()

import unittest
class Test(unittest.TestCase):
    def test1(self):
        self.assertEqual(solve('#.#'), 1)
    def test2(self):
        self.assertEqual(solve('#.##.'), 2)
    def test3(self):
        self.assertEqual(solve('.........'), 0)
    def test4(self):
        self.assertEqual(solve('#'), 0)
    def test5(self):
        self.assertEqual(solve('.'), 0)
    def test6(self):
        self.assertEqual(solve('#.'), 1)
    def test7(self):
        self.assertEqual(solve('##'), 0)
    def test8(self):
        self.assertEqual(solve('..'), 0)
    def test9(self):
        self.assertEqual(solve('.#'), 0)
    def test10(self):
        self.assertEqual(solve('#'*1000 + '.' * 999), 999)
    def test11(self):
        self.assertEqual(solve('#'*999 + '.' * 1000), 999)

Submission status: Wrong Answer

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


cnt = 0
for i in range(N):
    if S[-1 -i] == "#":
        cnt += 1
    else:
        break

for i in range(N):
    if S[i] == ".":
        continue

    print(min(S[i:].count("#") - cnt, S[i:].count(".")))
    exit()

print(0)

Submission status: Wrong Answer

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


for i in range(N):
    if S[i] == ".":
        continue

    print(min(S[i:].count("#"), S[i:].count(".")))
    exit()

print(0)

Submission status: Wrong Answer

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

ans = S.count("#.")
if ans == 0:
    print(0)
    exit()

prev = "."
c = [0]
ci = 0
for s in S:
    if s == "#":
        if prev == "#":
            c[ci] += 1
        else:
            ci += 1
            c.append(0)
            c[ci] += 1
        prev = "#"
    else:
        if prev == ".":
            c[ci] += 1
        else:
            ci += 1
            c.append(0)
            c[ci] += 1
        prev = "."

ans = 0
for i in range(1, len(c) - 1, 2):
    ans += min(c[i], c[i + 1])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = s.lstrip('.')
s = s.rstrip('#')
print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s = s.lstrip('.')
s = s.lstrip('#')
print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
h = 0
t = len(s)
while h < t and s[h] == '.':
    h += 1
while h<t and s[t-1] == '#':
    t -= 1
if t==h:
    print(0)
    exit()
s = s[h:t]
print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
h = 0
t = len(s)
while h < t and s[h] == '.':
    h += 1
while 0<t and s[t-1] == '#':
    t -= 1
s = s[h:t]
print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

Solution code:
input();print(input().count('#.'))

Submission status: Wrong Answer

Solution code:
print(input().count('#.'))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
max_w = S.count(".")
if max_w == 0 or max_w == N:
  print(0)
  exit()

ans = float("inf")
b, w = 0, max_w
for s in S:
  if s == "#":
    b += 1
  else:
    w -= 1
  ans = min(ans, b+w)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
max_w = S.count(".")
ans = float("inf")
b, w = 0, max_w
for s in S:
  if s == "#":
    b += 1
  else:
    w -= 1
  ans = min(ans, b+w)
print(ans)

Submission status: Wrong Answer

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

if '.' not in S:
    print(0)
    exit()
elif '#' not in S:
    print(0)
    exit()

black_sum = 0
white_sum = 0
for i in range(N):
    if S[i] == '#':
        black_sum += 1
    else:
        white_sum += 1

left_black = 0
right_white = white_sum
min_sum = 10 ** 9
for i in range(N):
    if S[i] == '#':
        left_black += 1
    else:
        right_white -= 1

    min_sum = min(min_sum, left_black + right_white)
print(min_sum)

Submission status: Wrong Answer

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

if '.' not in S:
    print(0)
    exit()
elif '#' not in S:
    print(0)
    exit()

black_sum = 0
white_sum = 0
for i in range(N):
    if S[i] == '#':
        black_sum += 1
    else:
        white_sum += 1

left_black = 0
right_white = white_sum
min_sum = 10 ** 9
for i in range(N - 1):
    if S[i] == '#':
        left_black += 1
    else:
        right_white -= 1

    min_sum = min(min_sum, left_black + right_white)
print(min_sum)