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:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from collections import Counter
#======================================================#
def main():
    n = II()
    s = IS()
    c = Counter(s)
    cnt_w = c['.']
    cnt_b = 0
    cnt = 10**9
    for si in s:
        if si == '#':
            cnt_b += 1
        else:
            cnt_w -= 1
        cnt = min(cnt, cnt_b+cnt_w)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    s = IS()
    cnt = 10**9
    cnt_w = 0
    for i in range(n-1):
        if s[i] == '#' and s[i+1] == '.':
            cnt_w += 1
    cnt = min(cnt_w, cnt)
    cnt_b = 0
    sl = list(s)
    for i in range(n-1):
        if sl[i] == '#' and sl[i+1] == '.':
            cnt_b += 1
            sl[i+1] = '#'
    cnt = min(cnt_b, cnt)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

if black==0 or white==0:
    print(0)
    exit()


tmptowhite=0

for i in range(n):
    if s[i]=="#":
        tmptowhite+=1

        lefttowhite=tmptowhite
        righttoblack=white -(i-tmptowhite)
    else:

        lefttowhite=tmptowhite
        righttoblack=white -(i+1-tmptowhite)
    
    #print(tmptowhite,lefttowhite,righttoblack)
    
    ans=min(lefttowhite+righttoblack,ans)

    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

if black==0 or white==0:
    print(0)
    exit()


tmptowhite=0

for i in range(n):
    if s[i]=="#":
        tmptowhite+=1

        lefttowhite=tmptowhite
        righttoblack=white -(i-tmptowhite)
    else:

        lefttowhite=tmptowhite
        righttoblack=white -(i+1-tmptowhite)
    
    print(tmptowhite,lefttowhite,righttoblack)
    
    ans=min(lefttowhite+righttoblack,ans)

    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

if black==0 or white==0:
    print(0)
    exit()


tmptowhite=0

for i in range(n):

    lefttowhite=tmptowhite
    righttoblack=white -(i-tmptowhite)
    ans=min(lefttowhite+righttoblack,ans)
    if s[i]=="#":
        tmptowhite+=1
    #print(tmptowhite,lefttowhite,righttoblack)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

if black==0 or white==0:
    print(0)
    exit()
if s[-1]=="#" and black==1:
    print(0)
    exit()

tmptowhite=0

for i in range(n):
    if s[i]=="#":
        tmptowhite+=1
    lefttowhite=tmptowhite
    righttoblack=white -(i+1-tmptowhite)
    ans=min(lefttowhite+righttoblack,ans)
    #print(tmptowhite,lefttowhite,righttoblack)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

if black==0 or white==0:
    print(0)
    exit()

tmptowhite=0

for i in range(n):
    if s[i]=="#":
        tmptowhite+=1
    lefttowhite=tmptowhite
    righttoblack=white -(i+1-tmptowhite)
    ans=min(lefttowhite+righttoblack,ans)
    #print(tmptowhite,lefttowhite,righttoblack)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())

mat=Counter(s)
black=mat["#"]
white=n-black

ans=10**100

tmptowhite=0

for i in range(n):
    if s[i]=="#":
        tmptowhite+=1
    lefttowhite=tmptowhite
    righttoblack=white -(i+1-tmptowhite)
    ans=min(lefttowhite+righttoblack,ans)
    #print(tmptowhite,lefttowhite,righttoblack)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
pre = '.'
b = 0
w = 0
for c in s:
    if c=='.':
        w += 1
    elif c=='#' and pre=='#':
        b += 1
    else:
        ans += min(b, w)
        b = 1
        w = 0
    pre = c
if pre=='.':
    ans += min(b, w)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S = str(input())

dp = [0]*(N+1)
temp = 0
for i in range(N):
    if S[i] == '.':
        temp += 1

for i in range(1,N+1):
    if S[i-1] == '.':
        dp[i] = dp[i-1]-1
    else:
        dp[i] = dp[i-1]+1

print(min(dp))

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S = str(input())

dp = [0]*N
temp = 0
for i in range(N):
    if S[i] == '.':
        temp += 1

if temp == N:
    print(0)
    exit()

dp[0] = temp

for i in range(1,N):
    if S[i-1] == '.':
        dp[i] = dp[i-1]-1
    else:
        dp[i] = dp[i-1]+1

print(max(0,min(dp)))

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S = str(input())

dp = [0]*N
temp = 0
for i in range(N):
    if S[i] == '.':
        temp += 1

if temp == N:
    print(0)
    exit()

dp[0] = temp

for i in range(1,N):
    if S[i-1] == '.':
        dp[i] = dp[i-1]-1
    else:
        dp[i] = dp[i-1]+1

print(min(dp))

Submission status: Wrong Answer

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

    # 白と黒の累積個数
    wt = [0]
    bk = [0]
    for s in S:
        w, b = wt[-1], bk[-1]
        if s == '.': w += 1
        else: b += 1
        wt.append(w)
        bk.append(b)

    # i番目までを白にして、i+1番目以降を黒にするときのコスト
    ans = 10**9
    for i in range(1, N+1):
        flip = bk[i] + wt[-1] - wt[i]
        ans = min(flip, ans)
    print(ans)

tenka1bc19_c()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
w=s.count('.')
if s[0]=='.':
    sm=1
else:
    sm=0
    
def change(y):
    total=(y+1-sm)+(w-sm)
    return total
mn=change(0)
for i in range(1,n):
    if s[i]=='.':
        sm += 1
    mn=min(mn,change(i))
print(mn)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
switch=0
count=0
for i in s:
    if i=='#':
        if switch==0:
            switch=1
    else:
        if switch==1:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
from collections import Counter
from copy import deepcopy

#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=list(ss())
darr=deepcopy(arr)
cnt1=0
cnt2=0
chk=Counter(arr)["#"]
for i in range(n-1):
    if arr[i]=="#":
        if arr[i+1]==".":
            arr[i+1]="#"
            cnt1+=1
    if darr[i]=="#":
        cnt2+=1

print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
from collections import Counter
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=list(ss())
cnt=0
chk=Counter(arr)["#"]
for i in range(n-1):
    if arr[i]=="#":
        if arr[i+1]==".":
            arr[i+1]="#"
            cnt+=1

if cnt>chk:
    print(chk)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=list(ss())
cnt=0
for i in range(n-1):
    if arr[i]=="#":
        if arr[i+1]==".":
            arr[i+1]="#"
            cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '#':
    b_total += 1
  if s[i] == '.':
    w_total += 1
if b_total == n:
  print(0)
else:
  b_cnt = 0
  w_cnt = 0
  ans = 10**6
  for i in range(n):
    if s[i] == '#':
      b_cnt += 1
    if s[i] == '.':
      w_cnt += 1
    cnt = b_cnt + (w_total - w_cnt)
    ans = min(ans, cnt)
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b_total = 0
w_total = 0
ans = 0
for i in range(n):
  if s[i] == '#':
    b_total += 1
  if s[i] == '.':
    w_total += 1
b_cnt = 0
w_cnt = 0
ans = 10**6
for i in range(n):
  if s[i] == '#':
    b_cnt += 1
  if s[i] == '.':
    w_cnt += 1
  cnt = b_cnt + (w_total - w_cnt)
  ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b_cnt = 0
w_cnt = 0
ans = 0
for i in range(n):
  if s[i] == '#' and w_cnt == 0:
    b_cnt += 1
  elif s[i] == '#' and w_cnt > 0:
    ans += min(b_cnt, w_cnt)
    if b_cnt > w_cnt:
      b_cnt += w_cnt + 1
      w_cnt = 0
    else:
      b_cnt = 1
      w_cnt = 0
  elif s[i] == '.':
    w_cnt += 1
ans += min(b_cnt, w_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b_cnt = 0
w_cnt = 0
ans = 0
for i in range(n):
  if s[i] == '#' and w_cnt == 0:
    b_cnt += 1
  elif s[i] == '#' and w_cnt > 0:
    ans += min(b_cnt, w_cnt)
    if b_cnt > w_cnt:
      b_cnt += 1
      w_cnt = 0
    else:
      b_cnt = 1
      w_cnt = 0
  elif s[i] == '.':
    w_cnt += 1
ans += min(b_cnt, w_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
b_cnt = 0
w_cnt = 0
ans = 0
for i in range(n):
  if s[i] == '#' and w_cnt == 0:
    b_cnt += 1
  elif s[i] == '#' and w_cnt > 0:
    ans += min(b_cnt, w_cnt)
    b_cnt = 1
    w_cnt = 0
  elif s[i] == '.':
    w_cnt += 1
ans += min(b_cnt, w_cnt)
print(ans)

Submission status: Wrong Answer

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

cnt = 0
flg = False
for s in S:
    if s == "#":
        break
    cnt += 1

wh = S.count(".", cnt)

print(min(wh, N-wh))

Submission status: Wrong Answer

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


cnt = [0,0]
flg = False
for s in S:
    if not flg:
        if s == "#":
            flg = True
        else:   
            continue

    if s == ".":
        cnt[0] += 1
    else:
        cnt[1] += 1

print(min(cnt))

Submission status: Wrong Answer

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


cnt = [0,0]
flg = False
for s in S:
    if not flg:
        if s == "#":
            flg = True 
        continue

    if s == ".":
        cnt[0] += 1
    else:
        cnt[1] += 1

print(min(cnt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ss = list(s)[::-1]

white = 0
black = 0
w = [0] * n
b = [0] * n

for i in range(n):
    if s[i] == '#':
        black += 1
    if ss[i] == '.':
        white += 1
    b[i] = black
    w[-i-1] = white

ans = 10**9

print(b)
print(w)

for i in range(n):
    if b[i] + w[i] < ans:
        ans = b[i] + w[i]

print(ans-1)

Submission status: Wrong Answer

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

flg = False
ans = 0

for i in s:
    if i == '#':
        flg = True

    if flg is True and i == '.':
        ans += 1

flg2 = False
ans2 = 0

ss = list(s)[::-1]

for i in ss:
    if i == '.':
        flg2 = True

    if flg2 is True and i == '#':
        ans2 += 1

print(min(ans, ans2))

Submission status: Wrong Answer

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

flg = False
ans = 0

for i in s:
    if i == '#':
        flg = True

    if flg is True and i == '.':
        ans += 1

print(ans)

Submission status: Wrong Answer

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

l = [0 for i in range(n)]
r = [0 for i in range(n)]
for i in range(1, n):
  rev = -(i+1)
  l[i] = l[i-1] + 1 if s[i-1] == "." else l[i-1]
  r[rev] = r[rev+1] + 1 if s[rev+1] == "#" else r[rev+1]

ans = 1e+9
for i in range(n):
  ans = min(ans, l[i] + r[i])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = list(input())
    bl = [0]*N
    wh = [0]*N

    from itertools import accumulate

    wh_num = 0
    for i in range(N):
        if S[i] == '#':
            bl[i] = 1
        else:
            wh[i] = 1
            wh_num += 1

    bl = [0] + bl
    wh = [0]+wh

    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    bl = list(accumulate(bl))
    wh = list(accumulate(wh))

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans = N
    for i in range(1, N + 1):
        ans = min(ans, bl[i]+(wh_num-wh[i]))
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
# Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = list(input())
    bl = [0]*N
    wh = [0]*N

    from itertools import accumulate

    wh_num = 0
    for i in range(N):
        if S[i] == '#':
            bl[i] = 1
        else:
            wh[i] = 1
            wh_num += 1

    bl = [0] + bl
    wh = [0]+wh

    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    bl = list(accumulate(bl))
    wh = list(accumulate(wh))

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans = 10**10
    for i in range(1, N + 1):
        ans = min(ans, bl[i]+(wh_num-wh[i]))
    print(ans)


resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
l = list(accumulate(map(int, input().translate(str.maketrans("#.","10")))))
q = l[-1]
m = INF = float("inf")
for i in range(n):
    m = min(m, l[i] + n - i - (q - l[i]) - 1)
print(m)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    B = S.count("#")
    W = S.count(".")

    # 左からi文字目までの白の数
    n_white = []
    if S[0] == ".":
        n_white.append(1)
    else:
        n_white.append(0)
    for i in range(1, N):
        if S[i] == ".":
            n_white.append(n_white[-1] + 1)
        else:
            n_white.append(n_white[-1])

    # ....##### の並びにする.境目に関して全探索
    ans = min(B, W)
    for i in range(1, N):
        # 白に変える数
        cnt = i + 1 - n_white[i]

        # 黒に変える数
        cnt += n_white[-1] - n_white[i]

        if cnt < ans:
            ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    S = list(reversed(S))
    for i in range(len(S)-1):
        if (S[i]==".")and(S[i+1]=="#"):
            count += 1
            S[i+1] =  "."

print(count)

Submission status: Wrong Answer

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :
    S = list(reversed(S))
    for i in range(len(S)-1):
        if (S[i]==".")and(S[i+1]=="#"):
            count += 1
            S[i] =  "."

print(count)

Submission status: Wrong Answer

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

S = list(S)
white_count = S.count(".")
black_count = S.count("#")
count = 0

if white_count < black_count:

    for i in range(len(S)-1):
        print(S[i],S[i+1])
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] = "#"
else :

    for i in reversed(range(len(S)-1)):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i] =  "."

print(count)

Submission status: Wrong Answer

Solution code:

from collections import Counter, deque, defaultdict
N = int(input())
S = input()

c = Counter(S)

fi = 0
for i in S:
    if i == "#":
        fi += 1
    else:
        break

if c["."] == 0:
    print(0)
else:
    print(max(0, c["#"] - fi))

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, defaultdict
N = int(input())
S = input()

c = Counter(S)

fi = 0
for i in S:
    if i == "#":
        fi += 1
    else:
        break

print(max(0, c["#"] - fi))

Submission status: Wrong Answer

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

S = list(S)
scount = S.count(".")
kcount = S.count("#")
count = 0
if scount < kcount:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] == "#"
else :
    for i in reversed(range(len(S)-1)):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i] == "."

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, defaultdict
N = int(input())
S = input()

c = Counter(S)
print(max(0, c["#"] - 1))

Submission status: Wrong Answer

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

S = list(S)
scount = S.count(".")
kcount = S.count("#")
count = 0
if scount < kcount:

    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i+1] == "#"
else :
    for i in range(len(S)-1):
        if (S[i]=="#")and(S[i+1]=="."):
            count += 1
            S[i] == "."

print(count)

Submission status: Wrong Answer

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

status = ""
ct = 0
for i in range(N):
    if S[i] == ".":
        status = "."
    elif status == "." and S[i] == "#":
        ct += 1
        S[i] == "."
    else:
        status = "#"
print(ct)

Submission status: Wrong Answer

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

S = list(S)
scount = 0
kcount = 0
for i in range(len(S)-1):
    if (S[i]=="#")and(S[i+1]=="."):
        kcount += 1
        S[i+1] == "#"

for i in range(len(S)-1):
    if (S[i]=="#")and(S[i+1]=="."):
        scount += 1
        S[i] == "."

if scount > kcount:
    print(kcount)
else:
    print(scount)

Submission status: Wrong Answer

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

S = list(S)
count = 0
for i in range(len(S)-1):
    if (S[i]=="#")and(S[i+1]=="."):
        count += 1
        S[i+1] == "#"

print(count)

Submission status: Wrong Answer

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

i=0
while s[0]==".":
    s=s[1:]
    if s=="":
        print(0)
        exit()

while s[-1]=="#":
  s=s[:-1]
  if s=="":
    print(0)
    exit()

#print(s)
print(min(s.count("."),s.count("#")))