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())
s=list(input())

b=s.count('#')
w=s.count('.')

ans=0
sflag=False
pflag=False
snum=0
pnum=0

for i in range(n):
    if s[i] == '#' and sflag and pflag:
        ans+=min(snum,pnum)
        snum=0
        pnum=0
        sflag=False
        pflag=False

    elif s[i] == '#':
        sflag = True
        snum+=1

    elif sflag == True and s[i] == '.':
        pflag=True
        pnum+=1

    elif ans>=b or ans>=w:
        break

#print(min(b,w))
print(min(b,w,ans+pnum))

Submission status: Wrong Answer

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

cnt=0
l = []
b = 1 if S[0] == "." else 0

for i in range(1, N):
    if S[i]==S[i-1]:
        cnt += 1
        if i == N-1:
            l.append(cnt+1)
    else:
        l.append(cnt+1)
        if i == N-1:
            l.append(1)
        cnt = 0

if len(l)<=1:
    print("0")
    exit()

s = 0
m = 1000000000
for i in range(b, len(l), 2):
    for j in range(b, i, 2):
        print(i, j, l[j])
        s += l[j]
    for j in range(i+1, len(l), 2):
        print(i, j, l[j])
        s += l[j]
    m = min(s, m)

print(l)
print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


from sys import stdin



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


# read data for n sequences.
n = stdin.readline()
N = int(n)
n = stdin.readline()
S = str(n)

#data = [int(stdin.readline().rstrip()) for _ in range(n)]

out=[]
count=0
for i,l in enumerate(S):
	if i < N:	
		if l == "#":
			count+=1

# count black on right
countX=0
for l in reversed(S):
	if l == "#":
		countX+=1
	else:
		break

count2=N-count
N-=countX
count-=countX
print(min([count,count2]))

Submission status: Wrong Answer

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

x=0
a=0
b=0

for i in range(N):
    if S[i]==".":
        a+=1
    else:
        b+=1

if a==N or b==N:
    print("0")
elif a>=b:
    x=a-b
    print(x)
else:
    x=b-a
    print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = S.count(".")
if S[0] == ".":
    count -= 1
if S.count(".") == N:
    count = 0
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
blacknum = []
whitenum = []
cnt = 0
now = 0
blackcnt = 0
whitecnt = 0

for i in range(N):
    if now == 0 and S[i] == '#':
        whitenum.append(whitecnt)
        blackcnt += 1
        now = 1
    elif now == 1 and S[i] == '.':
        blacknum.append(blackcnt)
        whitecnt += 1
        now = 0
    elif now == 0 and S[i] == '.':
        whitecnt += 1
    else:
        blackcnt += 1

if now == 0:
    whitenum.append(whitecnt)
else:
    blacknum.append(whitecnt)
if len(whitenum) == len(blacknum):
    whitenum.append(whitecnt)

ans = 0
for i in range(len(blacknum)):
    if blacknum[i] <= (whitenum[-1] - whitenum[i]):
        ans = blacknum[i]
    else:
        ans += whitenum[-1] - whitenum[i]
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
allblack = S.count('.')
allwhite = S.count('#')
firstblack = S.find('#')
if firstblack != -1:
    lastblack = S[firstblack:].count('.')
else:
    lastblack = 2 ^ 32
#print('allblack: ' + str(allblack))
#print('allwhite: ' + str(allwhite))
#print('lastblack: ' + str(lastblack))
print(min(allblack, allwhite, lastblack))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    line = list(input())
    flag = False
    cnt_W = 0
    cnt_B = 0
    for i in range(N):

        if line[N-i-1] ==".":
            flag = True
        if flag == True:
            for j in range(N-i):
                if line[j] ==".":
                    cnt_W +=1
                else:
                    cnt_B +=1
            break
    return min(cnt_W,cnt_B)

print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
list = [0]*N

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

for i in range(N-1):
    if list[i] == 1 and S[i+1] == '.':
        list[i+1] = 1

print(sum(list))

Submission status: Wrong Answer

Solution code:
N = int(input())

S = str(input())

S = list(S)

cnt = 0
cnt2 = 0
for i in range(len(S)):
    if i == len(S)-1:
        break
    elif S[i] == "#" and S[i + 1] == ".":
        cnt = cnt + 1
        
for i in range(len(S)):
    if i == len(S)-1:
        break
    elif S[i+1] == "#" and S[i] == ".":
        cnt2 = cnt2 + 1
       
if cnt < cnt2:
    print(cnt)
else:
    print(cnt2)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
#" . #
#  b=black#
#  w=white.
f=[0,1][s[0]=="#"]
g=[0,1][s[0]=="."]
b=[f]
w=[0]
#print(b,w)
for i in s:
#    print(w)
    if f==1 and i=="#":
        b[-1]+=1
    elif f==1 and i==".":
        f=0
        if w[-1]!=0: w.append(1)
        else: w[-1]=1
    elif b[-1]!=0 and f==0 and i==".":
        w[-1]+=1
    elif f==0 and i=="#":
        f=1
        if b[-1]!=0: b.append(1)
        else: b[-1]=1
x=sum(b)
y=sum(w)
if s[-1]=="#": x-=b[-1]

ans=min(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [1 if x == '.'  else 0 for x in list(input())]

min_cost = 2*10**5
for i in range(1, N, 1):
    head = S[:i]
    tail = S[i:]
    cost = (i - sum(head)) + sum(tail)

    if min_cost > cost:
        min_cost = cost
        
print(min_cost)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

# 四方向
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

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

ind = S.find("#")
ans = S[ind+1:].count(".")

ind = S[::-1].find(".")
rans = S[::-1][ind+1:].count("#")

print(min(ans, rans))

Submission status: Wrong Answer

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

count = 0
sum1 = 0
sum2 = 0
for i in enumerate(S):
  if (i == "#"):
    sum1 += 1
  else:
    sum2 += 1
    
if (sum1 >= sum2):
  for i,char in enumerate(S):
    if (i < len(S) - 1):
      if (char == "#"):
        if (S[i+1] == "."):
          count += 1
else:
  new_S = S[::-1]
  for i,char in enumerate(new_S):
    if (i < len(S) - 1):
      if (char == "."):
        if (new_S[i+1] == "#"):
          count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
"""
python3 a.py < input.txt
"""
import math
import itertools as it
import heapq

N=int(input())
S=input()
lb=None
for i in range(N):
    if S[N-i-1] == "#":
        lb=N-i-1
if lb==None:
    print(0)
    exit(0)
rw=None
for i in range(N):
    if S[i]==".":
        rw=i
if rw==None:
    print(0)
    exit(0)
nb=0
for i in range(lb, N):
    if S[i] == ".":
        nb = nb+1
nw=0
for i in range(0, rw):
    if S[i] == "#":
        nw = nw+1

if lb != None:
    print(min(nb, nw))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#S=input()
#import fractions
#lis=list(map(int,input().split()))

n=int(input())
s=input()

count=0 #black
flag=-1 #first black
for i in range(n):
    if s[i]=="#":
        count+=1
        if flag==-1:
            flag=i
if count==0:
    ans=0
else:
    a=count-flag
    b=n-count
    ans=min(a,b)




print(ans)

Submission status: Wrong Answer

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

A = S.count("#")
B = S.count(".")

if(A == 0 or B == 0):
    print("0")
else:
    P = S.find("#")
    O= print(S.count(".",P))

Submission status: Wrong Answer

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

ans=10**9+7
lb=0
rb=S.count('#')
rw=S.count('.')

if rb==0 or rw ==0:
    ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
S = input()
col = "#."
hoge = 0
C = [0]
for i in range(N):
    if S[i] == col[hoge]:
        C[-1] += 1
    else:
        C.append(1)
        hoge = (hoge+1)%2
B,W =0,0
for i in range(len(C)):
    if i % 2 == 0:
        B += C[i]
    else:
        W += C[i]
if C[0] == 0:
    W -= C[1]
if len(C)%2 == 1:
    B -= C[-1]
print(min(B,W))

Submission status: Wrong Answer

Solution code:
def c_stones(N, S):
    import itertools
    s = [(k, len(list(v))) for k, v in itertools.groupby(S)]
    if s[0][0] == '.':
        del s[0]
    if len(s) > 0 and s[-1][0] == '#':
        del s[-1]
    ans1, ans2 = 0, 0
    for i in range(len(s)):
        if i % 2 == 0:
            ans1 += s[i][1]
        else:
            ans2 += s[i][1]
    return min(ans1, ans2)

N = int(input())
S = input()
print(c_stones(N, S))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
w,b = 0,0
for s in S:
    if s == '.':
        w += 1
    else:
        b += 1

if b > w:
    if S[len(S)-1] == '#':
        print(w-1)
    else:
        print(w)
else:
    if S[len(S)-1] == '#':
        print(b-1)
    else:
        print(b)

Submission status: Wrong Answer

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

cnt = 0
items = list(s)
num1 = items.count('#')
num2 = items.count('.')

ans1 = min(num1, num2)

ind = s.find('.')
sub1 = s[:ind]
sr = ''.join(reversed(list(s)))
ind = sr.find('#')
sub2 = sr[:ind]

num1 = sub1.count('#')
num2 = sub2.count('.')
ans2 = min(num1, num2)


print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s =  list(input())
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:
N = int(input())
S = input()

flag = True
cnt_b = 0
cnt_w = 0

for i in S:
    if flag and i == ".":
        #print("debag flag")
        continue
    if i == "#":
        #print("debag b")
        flag = False
        cnt_b += 1
    else:
        #print("debag w")
        cnt_w += 1

if cnt_b < cnt_w:
    print(cnt_b)
else:
    print(cnt_w)

Submission status: Wrong Answer

Solution code:
import sys
a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
prev_haichi = '.'
black_count = 0
count = 0
for i in range(num):
    each_haichi = haichi[i]
    if prev_haichi == '#' and each_haichi == '.':
        count += 1
        prev_haichi = '#'
    else:
        prev_haichi = each_haichi
    if each_haichi == '#':
        black_count += 1
print(min(black_count, count))

Submission status: Wrong Answer

Solution code:
import re
n = int(input())
s =input()
ss = ''.join(re.findall("#\.+",s))
print(min(ss.count('#'),ss.count('.')))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def main():
    input()
    s = input()

    # 最初に黒い石が出現した後に出現した"."と"#"のそれぞれの総数のうち、最小のものを返す
    b_num = 0
    w_num = 0
    is_start = False
    for c in s:
        if not is_start and c != "#":
            continue
        if c == "#":
            is_start = True
        if is_start:
            if c == ".":
                w_num += 1
            if c == "#":
                b_num += 1

    return min(w_num, b_num)


print(main())

Submission status: Wrong Answer

Solution code:
def solve():
  N = int(input())
  S = input()
  foundBlack = False
  black = S.count('#')
  white = N - black
  black -= N - S.rfind('.') - 1
  white -= S.find('#')
  return min(black, white)

print(solve())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

n = int(input())

s = list(input())

count = 0

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

        if [i-1] == '.':
            s[i] = '.'
            count += 1
        else:
            s[i+1] = '#'
            count += 1
    i += 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	S = input()
	S = S[:-1]

	ans = 0
	flg = False
	for i in S:
		if i == "#" and flg == False:
			flg = True
			continue
		if flg == True and i == ".":
			ans += 1

	print(ans)

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
l=list(input())
m=0
lm=[]
for i in range(len(l)-1):
    if (l[i]=="#" and l[i+1]=="."):
        m=i+1
        lm=l[m:]
        break
#a=lm.count(".")
b=lm.count(".")
a=l.count("#")
ans=min(a,b)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
dst1 = 0
dst2 = 0
first_kuro = False
for c in s:
    if first_kuro:
        if c == ".":
            dst1 += 1
    if c == "#":
        first_kuro = True
first_siro = False
for c in reversed(s):
    if first_siro:
        if c == "#":
            dst2 += 1
    if c == ".":
        first_siro = True
print(min(dst1,dst2))

Submission status: Wrong Answer

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

w2b_cnt = 0 if '#' not in s else s.count('.')
b2w_cnt = 0 if '.' not in s else s.count('#')

print(min(w2b_cnt, b2w_cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())+1
S = '.' + input()
b,w,flg,ans = 0,0,0,0
for i in range(N):
  if S[-i+1] == '.':
    if flg == 0:
      w += 1
      flg = 1
    elif flg == 1:
      w +=1
    elif flg == 2:
      ans += min(b,w)
      b,w = 0,1
      flg = 1
  elif flg == 1:
    b+=1
    flg = 2
  elif flg == 2:
    b+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S == '.' * N:
  print(0)
else:
  first = 0
  for i in range(1,N+1):
    if S[i-1] == '#':
      first = i
      break
  out1 = 0
  for i in range(first+1,N+1):
    if S[i-1] =='.':
      out1 += 1
  second = 0
  for i in range(1,N+1):
    if S[N-i] == '.':
      second = i
      break
  out2 = 0
  for i in range(second+1,N+1):
    if S[N-i] =='#':
      out2 += 1
  out3 = 0
  for i in range(1,N+1):
    if S[i-1] =='.':
      out3 += 1
  out4 = N-out3
  print(min(out1,out2,out3,out4))

Submission status: Wrong Answer

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

if N == 1:
    print(0)
    exit()
if N == 2:
    if S[0] == "#" and S[1] == ".":
        print(1)
    else:
        print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
black = '#'
white = '.'

def main():
    n = int(input())
    s = list(input())

    ans = 0

    for i in range(len(s)):
        if needToChange(s, i):
            s[i + 1] = black
            ans += 1

    print(ans)

def needToChange(s, i):
    if s[i] == white:
        return False
    if i >= len(s) - 1:
        return False
    if s[i + 1] == white:
        return True
    return False

main()

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    S = list(input())
    
    count_sharp = S.count('#')
    count_dot = S.count('.')
    # print(count_sharp, count_dot, count_sharp < count_dot)
    count = 0

    for i in range(1, len(S)):
        
        # print(S, end=' ')
        one = S[i-1]
        two = S[i]
        
        if count_sharp <= count_dot:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            elif (one == '#') and (two == '#'):
                S[i-1] = '.'
                count += 1
        else:
            if (one == '#') and (two == '.'):
                count += 1
                S[i-1] = '.'
            # elif (one == '#') and (two == '#'):
            #     S[i-1] = '.'
            #     count += 1
        # print(count, end=' ')
        # print(S)

    print(count)
    # #..#.#....##...# -> (.)..(.).(.)....(.)(.)...#

main()

Submission status: Wrong Answer

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

Color=[]
CNT=[]	#Count
cnt=0
prev=""
for i in range(N):
	if i==0:
		if S[i]=="#": Color.append("b")
		else: Color.append("w")
		cnt+=1
	else:
		if prev==S[i]:
			cnt+=1
		else:
			CNT.append(cnt)
			if S[i]=="#": Color.append("b")
			else: Color.append("w")	
			cnt=1	

		prev=S[i]
else:
	CNT.append(cnt)

l=len(Color)

ans=0
for i in range(l-1):
	if Color[i]=="b":
		ans+=min(CNT[i] , CNT[i+1])

print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s1 = '#'
i = 0
slis = []
ini = True

for s in S:
  if s == s1:
    i += 1
  if s != s1:
    if ini:
      slis.append(i)
      ini = False
    else:
      slis.append(i + 1)
    s1 = s
    i = 0

slis.append(i+1)

if S.startswith('.'):
  sum1 = sum(slis[2::2])
  sum2 = sum(slis[3::2])
elif S.endswith('#'):
  sum1 = sum(slis[0:-1:2])
  sum2 = sum(slis[1:-1:2])
else:
  sum1 = sum(slis[0::2])
  sum2 = sum(slis[1::2])

print(slis)
print(min(sum1, sum2))

Submission status: Wrong Answer

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


R=[]
for i in range(N-1):
  if (S[i] == '.') and (S[i+1] == '#'):#条件を絞る
  	R.append(S[0:i].count('#')+S[i:N].count('.'))
#全て白/全て黒を別途確認
R.append(S.count('#'))
R.append(S.count('.'))
print(min(R))



"""別パターン→これはダメ
#左から順に処理
R=[]
sig=0
for i in range(N-1):
  if (S[i] == '#') and (S[i+1] == '.'):
    #この場合、ここを'##'にするか、それより左全て'.'にするか
    # '##'にする場合
    R.append(S[i+1:N].count('.')+sig)
    # '..'にする場合
    S=S[0:i] + '.' + S[i+1:N]
    sig+=1#累積置換回数

#Sが全て'.'になっている場合が取れていないので追加
flg=True
for i in range(N):
  if S[i]=='#':
    flg=False
if flg:
  R.append(sig)

print(min(R))
"""

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S_list = [S[i] for i in range(len(S))]

t = 0
kekka = 0
count_sharp = 0
count_dot = 0

for x in S_list:
    if x == "#":
        count_sharp += 1
    else:
        count_dot += 1


if S_list[-1] == "#":
    if count_sharp > count_dot:
        for x in S_list:
            if x == ".":
                kekka += 1

    else :
        for x in S_list:
            if x == "#":
                kekka += 1
        
        kekka -= 1

else :
    if count_sharp >= count_dot:
        for x in S_list:
            if x == ".":
                kekka += 1
        kekka -= 1
    else :
        for x in S_list:
            if x == "#":
                kekka += 1

print(kekka)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
x = sum(1 if (s[i] == "#" and s[i + 1] == ".") else 0 for i in range(n-1))
y = sum(0 if (s[i] == "#" and s[i + 1] == ".") else 1 for i in range(n-1))
print(min(x, y))

Submission status: Wrong Answer

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

counter1=0
counter2=0
flag1=0
flag2=0
for i in range(N):

    if flag1 ==0:
        if moji[i]=="#":
            flag1=1
    elif flag1==1:
        if moji[i]==".":
            counter1+=1

    if flag2==0:
        if moji[N-i-1]==".":
            flag2=1
    elif flag2==1:
        if moji[N-i-1]=="#":
            counter2+=1

print(min(counter1,counter2))

Submission status: Wrong Answer

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

first = S[0]
count = 0
if first == '#':
    for i in S:
        if i == '.':
            count += 1
else:
    for i in S:
        if i == '#':
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
BS = []
WS = []
BS += S
WS += S

b_count=0
w_count=0

for i in range(N-1):
    if BS[i]=='#' and BS[i+1]=='.' :
        BS[i+1]='#'
        b_count+=1
    if WS[N-(i+1)]=='.' and WS[N-(i+2)]=='#' :
        WS[N-(i+2)]='.'
        w_count+=1
ans = b_count if w_count==0 else w_count
if b_count != 0 and w_count != 0:
    ans = min(b_count,w_count)
print(ans)

Submission status: Wrong Answer

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

S_list = list(S)
firstBlack = N
countStone = 0
for i in range(0, N):
  if(S_list[i] == "#"):
    firstBlack = i
    break

countChangeWhite = S_list[firstBlack:N].count(".")
countChangeBlack = S_list.count("#")

if(countChangeBlack < countChangeWhite):
  print(countChangeBlack)
else:
  print(countChangeWhite)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
count1=0
count2=0
for i in range(n-1):
    if(s[i]=='#'):
        if(s[i+1]=='.'):
            count1+=1
        else:
            continue
    else:
        continue
for j in range(n-1):
    if(s[i]=='.'):
        if(s[i+1]=='#'):
            count2+=1
        else:
            continue
    else:
        continue
print(min(count1,count2))

Submission status: Wrong Answer

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

a=0
b=0

for i in range(N):
	if S[i]=='#':
		a+=1
	else:
		b+=1
print(min(a,b))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
s2 = s.copy()
cnt1 = 0
for i in range(n-1):
    if s[i] == "#" and s[i+1] ==".":
        s[i+1] = "#"
        cnt1 += 1
cnt2 = 0
for i in range(1,n)[::-1]:
    if s2[i] == "." and s2[i-1] == "#":
        s2[i-1] = "."
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
left=0
right=0
for left in range(n-1):
  if s[left]=='#' and s[left+1]=='.':
    right=left+1
    while s[right]=='.' and right < n-1:
        right+=1
    cnt+=right-1-left
    left=right+1
  else:
    left+=1

if s.count('.')==n:
  print(0)
else:  
  print(cnt if s[-1]=='#' else cnt+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N =  input()
S =  input()

n = S.find("#")
m = S.rfind(".")
if n < 0 or m < 0:
  print(0)
else:
  print(min(S[n:].count("."), S[:m+1].count("#")))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
 
count=0
    
if N!=1:
    for i in range(1,N):
        if S[i-1]=="#":
            if S[i]=="#":
               count=count+0
            elif S[i]==".":
                count=count+1
             #S[i]=change_string(S[i])
print(count)

Submission status: Wrong Answer

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

count = 0

result1 = s.count('#')
result2 = s.count('.')


for x in s:
    count += 1
    if x != '.':
        break
    
    
result3 = s[count:].count('.')


sorted(s,reverse = True)
count = 0

for x in s:
    count += 1
    if x != '#':
        break
    
result4 = s[count:].count('#')

print(min(result1,result2,result3,result4))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if S.count("#") != 0:
  if S.count("#") < S.count("."):
    print(S.count("#"))
  else:
    print(S.count("."))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	S = input()
	S = S[:-1]

	ans = 0
	flg = False
	for i in S:
		print(i)
		if i == "#" and flg == False:
			flg = True
			continue
		if flg == True and i == ".":
			ans += 1

	print(ans)

	

	
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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.count("#."))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1, N):
    if len(set(S)) == 1:
        print(S[0] * N)
        exit()
    if S[i-1] == '#' and S[i] == '.':
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

ans = 0
answ = 0
ansb = 1
c = 0

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

if c == 0:
    print(0)

else:

    for i in range(n):

        if s[i] == "#":

            for j in range(n-i-1):
                
                if s[i+1+j] == ".":
                    answ += 1
                else:
                    ansb += 1

            if ansb <= answ:
                ans = ansb
            else:
                ans = answ   

            if answ == 0:
                ans = 0

            print(ans)
            break

Submission status: Wrong Answer

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

cnt = 0
for i in S:
    if i == '#':
        cnt += 1
    else:
        break

ANS1 = S[cnt:].count('.') 



cnt = 0
newS = ''.join(list(reversed(S)))
for i in newS:
    if i == '.':
        cnt += 1
    else:
        break

ANS2 = newS[cnt:].count('#') 

print(min(ANS1, ANS2))

Submission status: Wrong Answer

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

if '.' not in s or '#' not in s:
  print(0)
elif '#.' not in s:
  print(0)
else:
  if s[n-1] == '#':
    s = s[:s.rfind('.')+1]
  if '#.' in s:
    s = s[s.find('#'):]
  print(min(s.count('.'), s.count('#')))

Submission status: Wrong Answer

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

tmp = S[0]
count = 0

Blist = []
Wlist = []

if tmp == '.':
    Blist.append(0)

for i in range(N):
    if S[i] == tmp:
        count += 1
    else:
        if tmp == '#':
            Blist.append(count)
        else:
            Wlist.append(count)
        count = 1
        tmp = S[i]

if S[-1] == '#':
    Blist.append(count)
else:
    Wlist.append(count)

counter = []

if len(Wlist)==0:
    print(0)
elif len(Wlist)==1:
    print(min(Wlist[0], N-Wlist[0]))
else:
    for i in range(len(Wlist)+1):
        tmpB = sum(Blist[:i])
        tmpW = sum(Wlist[i:])
        counter.append(tmpB + tmpW)
        print(min(counter))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = S.count('#.')
counter = 0
for i in range(tmp):
    count = S.find('#.') + 1
    S_list = list(S)
    for i in range(count, len(S_list)):
        if S_list[i] == '.':
            counter += 1
            S_list[i] = '#'
    S = ''.join(S_list)
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cmp1,cmp2 = 0,0

if s.count('.') == n:
    print('0')
else:
    cmp1 = s[s.index('#'):].count('.')
    reverse_s = s[::-1]
    cmp2 = reverse_s[reverse_s.index('#'):].count('#')
    print(min(cmp1,cmp2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
S = input().strip()

def stone_cnt(idx):
  return S[:idx].count("#") + S[idx:].count(".")

pre = 2 * 10 ** 5

for i in range(len(S)):
  ans = stone_cnt(i)
  if ans > pre:
    break
  pre = ans

print(pre)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt = 0
cnt2 = 0
tmp = 0
tmp2 = 0
ans = 10**9
for i in s:
    if i=="#":
        cnt += 1
    else:
        cnt2 += 1
for i in s:
    if i=="#":
        tmp += 1
    else:
        tmp2 += 1
    ans = min(ans,tmp+cnt2-tmp2)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
S_ptn1=S[::-1]
cnt=0
cnt_ptn1=0
for i in range(N-1):
    if S[i]=='#' and S[i+1]=='.':
        S[i+1]='#'
        cnt+=1
for i in range(N-1):
    if S_ptn1[i]=='.' and S_ptn1[i+1]=='#':
        S[i+1]='.'
        cnt_ptn1+=1
if cnt<cnt_ptn1:
    print(cnt)
else:
    print(cnt_ptn1)

Submission status: Wrong Answer

Solution code:
# n=int(input())
# s=list(input())
# s2=s[:]
# s2.reverse()
# c=0
# for i in range(len(s)):
#   a=s[i]
#   if a=='#':
#     if i!=len(s)-1 and s[i+1]=='.':
#       s[i+1]='#'
#       c+=1
# c2=0
# for i in range(len(s2)):
#   a=s2[i]
#   if a=='.':
#     if i!=len(s2)-1 and s2[i+1]=='#':
#       s2[i+1]='.'
#       c2+=1
# print(s,s2)
# print(min(c,c2))

n=int(input())
s=list(input())
l=[]
a=s[0]
b=a
c=1
for x in s[1:]+['a']:
  if a==x:
    c+=1
  else:
    a=x
    l.append(c)
    c=1
cx=0
if b=='#':
  for i in range(len(l)//2):
    cx+=(min(l[2*i],l[2*i+1]))
else:
  l2=l[1:]+[0]
  for i in range(len(l2)//2):
    cx+=(min(l2[2*i],l2[2*i+1]))
print(cx)

Submission status: Wrong Answer

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


black=0
white=0
for st in s:
  if st=="#":
    black=black+1
  else:
    white=white+1
    
change=0
s = list(s)
now=-1

if black>white:
  while(now!=0):
    now=0
    for i in range(n-1):
      if s[i]=="#" and s[i+1]==".":
        change=change+1
        now=now+1
        s[i+1]="#"

else:
  while(now!=0):
    now=0
    for i in range(n-1):
      if s[i]=="#" and s[i+1]==".":
        change=change+1
        now=now+1
        s[i]="."

if change > n - change:
  change=n-change
print(change)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r1=S.count("#")
r2=N-r1

it1=0
it2=N-1
it1f=False
it2f=False
r3=0
isLeft=None

while it1<it2:
  if S[it1]!=".":
    if it1f==True and it2f==True:
      r3+=1
      it1+=1
      it1f=False
    else:
      it1f=True
  else:
    it1+=1

  if S[it2]!="#":
    if it1f==True and it2f==True:
      r3+=1
      it2-=1
      it2f=False
    else:
      it2f=True
  else:
    it2-=1



print(min((r1,r2,r3)))