Problem:


気象予報士 (Weather Forecaster)

問題

JOI 市は南北方向に H キロメートル，東西方向に W キロメートルの長方形の形をしており，H &times; W 個の 1 キロメートル四方の小区画に区切られている．北から i 番目，西から j 番目の小区画を (i, j) と表す．

各小区画は上空に雲があるか雲がないかのどちらかである．すべての雲は，1 分経つごとに 1 キロメートル東に移動する．今日は実に天気が良いため，JOI 市の外から JOI 市内に雲が移動してくることはない．

今，各小区画の上空に雲があるかないかがわかっている．気象予報士であるあなたは，各小区画について，今から何分後に初めてその小区画の上空に雲が来るかを予測することになった．

各小区画について，今から何分後に初めてその小区画の上空に雲が来るか求めよ．

入力

入力は 1 + H 行からなる．

1 行目には，整数 H, W (1 ≤ H ≤ 100, 1 ≤ W ≤ 100) が空白を区切りとして書かれている．これは，JOI 市が H &times; W 個の 1 キロメートル四方の小区画に区切られていることを表す．

続く H 行のうちの i 行目 (1 ≤ i ≤ H) には W 文字からなる文字列が書かれている．W 文字のうちの j 文字目 (1 ≤ j ≤ W) は，小区画 (i, j) の上空に，今，雲があるかどうかを表す．雲がある場合は文字 'c' (英小文字) が，雲がない場合は文字 '.' (ピリオド) が書かれている．

出力

出力は H 行からなり，それぞれの行は空白を区切りとした W 個の整数からなる．出力の i 行目の j 番目の整数 (1 ≤ i ≤ H, 1 ≤ j ≤ W) は，今から何分後に初めて小区画 (i, j) の上空に雲が来るかを表さなければならない．ただし，今すでに小区画 (i, j) の上空に雲がある場合は 0 を，何分経っても小区画 (i, j) の上空に雲が来ない場合は -1 を出力せよ．

出力の各行の行頭と行末には余計な空白を入れないこと．

入出力例

  
入力例 1

  

3 4
c..c
..c.
....

   
出力例 1

   

0 1 2 0
-1 -1 0 1
-1 -1 -1 -1

  
入力例 2

  

6 8
.c......
........
.ccc..c.
....c...
..c.cc..
....c...

   
出力例 2

  

-1 0 1 2 3 4 5 6
-1 -1 -1 -1 -1 -1 -1 -1
-1 0 0 0 1 2 0 1
-1 -1 -1 -1 0 1 2 3
-1 -1 0 1 0 0 1 2
-1 -1 -1 -1 0 1 2 3

入出力例 1 では，JOI 市は 3 &times; 4 個の小区画に区切られている．今の JOI 市の雲の状況は以下の通りである．図の上が北を表す．

この後，1 分ごとに雲は以下のように移動する．

問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
3 4
c..c
..c.
....


Sample output:
0 1 2 0
-1 -1 0 1
-1 -1 -1 -1

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ans = []
for _ in range(h):
  s = input()
  lst = []
  acc = -1
  for c in s:
    if c == "c":
      acc = 0
    elif acc == -1:
      pass
    else:
      acc += 1
    lst.append(acc)
  ans.append(lst)
for lst in ans:
  print(*lst)

Submission status: Accepted

Solution code:
# coding: utf-8

H, W = list(map(int, input().split(' ')))
sections = [list(input()) for i in range(H)]

crowds = [[-1 for w in range(W)] for h in range(H)]

for h in range(H):
    c = -1
    for w in range(W):
        if c >= 0: c += 1
        if sections[h][w] == 'c': c = 0
        crowds[h][w] = c

for row in crowds:
    print(' '.join(list(map(str, row))))

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split())

map = []
for i in xrange(n):
	map.append(list(raw_input()))
	if not 'c' in map[i]:
		map[i] = [-1 for _ in xrange(m)]
		continue
	elif map[i][0] == '.':
		for j in xrange(m):
			if map[i][j] == '.':
				map[i][j] = -1
			else : break
	for j in xrange(m):
		if map[i][j] == 'c':
			map[i][j] = 0
			hoge = 0
			for k in xrange(j + 1, m):
				hoge += 1
				if map[i][k] == 'c' : break
				else : map[i][k] = hoge
				
for var in map:
	for vin in var:
		print vin,
	print

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
x = [raw_input() for i in xrange(n)]

y = [[0] * m for i in xrange(n)]
for i in range(n):
	k = -1
	for j in xrange(m):
		if x[i][j] == 'c':
			k = 0
		y[i][j] = k
		k += k != -1

for i in xrange(n):
	print ' '.join(map(str, y[i]))

Submission status: Accepted

Solution code:
H,W = map(int, raw_input().split())
for y in range(H):
    S = raw_input()
    t = -1
    for x in range(W):
        if S[x]=="c":
            t = 0
        elif t>=0:
            t += 1
        print t,
    print

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
ans = [[0] * w for i in range(h)]
c_m = []
for i in range(h):
    c_lis = input()
    c_m.append(list(c_lis))
for j in range(h):
    for k in range(w):
        if ans[j][k] == 0 and c_m[j][k] == '.':
            ans[j][k] = -1
        elif c_m[j][k] == 'c':
            for l in range(w - k):
                ans[j][k + l] = l
for m in range(h):
    cha = str(ans[m][0])
    for n in range(w -1):
        cha = cha + " " + str(ans[m][n + 1])
    print(cha)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
while h:
    h-=1
    n=input()
    c=-1
    for i in range(w-1):
        if n[i]=='c':c=0
        print(c,end=" ")
        if c!=-1:c+=1
        if n[i+1]=='c':c=0
    print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
h, w = map(int, input().split())
cloud = [[i for i in input()] for i in range(h)]
flag = 0 #1?????¨????????????
cnt = 0 
for i in range(h):
    for j in range(w):
        if j==w-1 and flag==0 and cloud[i][j]=='.':
            print(-1, end='')
        elif j==w-1 and cloud[i][j]=='c':
            print(0, end='')
            flag = 1
            cnt = 0
        elif j==w-1 and cloud[i][j]=='.':
            cnt += 1
            print(cnt, end='')
        elif flag==0 and cloud[i][j]=='.':
            print(-1, end=' ')
        elif cloud[i][j]=='c':
            print(0, end=' ')
            flag = 1
            cnt = 0
        else:
            cnt += 1
            print(cnt, end=' ')
    print()
    cnt = 0
    flag = 0

Submission status: Accepted

Solution code:
h,w=[int(s)for s in input().split(" ")]
map_=[[True if c=='c' else False for c in input()]for i in range(h)]
dis=[['' for i in range(w)]for j in range(h)]
for i in range(h):
    distance=-1
    for j in range(w):
        if map_[i][j]==True:distance=0
        elif distance!=-1:distance+=1
        dis[i][j]=str(distance)
for d in dis:
    print(' '.join(d))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    cnt = -1
    res = []
    for j in range(W):
        if s[j] == 'c':
            cnt = 0
        else:
            if cnt != -1:
                cnt += 1
        res.append(cnt)
    print(*res)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
c = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    p = -1
    for j in range(w):
        if s[i][j] == ".":
            if p == -1:
                c[i][j] = -1
            else:
                p += 1
                c[i][j] = p
        else:
            p = 0
            c[i][j] = p
for i in c:
    print(" ".join(map(str, i)))

Submission status: Accepted

Solution code:
# AOJ 0610: Weather Forecaster
# Python3 2018.7.2 bal4u

import sys
from sys import stdin
input = stdin.readline

h, w = map(int, input().split())
ans = [[0 for c in range(w)] for r in range(h)]
arr = [input().strip() for r in range(h)]
for r in range(h):
	p = -1
	for c in range(w):
		if arr[r][c] == 'c': p = c
		ans[r][c] = -1 if p < 0 else c-p
for r in range(h): print(*ans[r])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    cnt = -1
    res = []
    for j in range(W):
        if s[j] == 'c':
            cnt = 0
        else:
            if cnt != -1:
                cnt += 1
        res.append(cnt)
    print(*res)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for _ in range(H): A.append((input().strip()))
for h in range(H):
	for w in range(W):
		if A[h][w]=='c':
			tmp = 0
		elif A[h][0:w].count('c')==0:
			tmp = -1
		else:
			tmp = w-A[h][0:w].rindex('c')
		if w == W-1:
			print(tmp)
		else:
			print(tmp, end=' ')

Submission status: Accepted

Solution code:
H,W=[int(i) for i in input().split(" ")]

city=[]
for i in range(H):
    C=input()
    row=[]
    timer=-1000
    for c in C:
        if c=="c":
            timer=0
            row.append(timer)
        else:
            timer+=1
            row.append(timer)
    city.append(row)


for i in range(H):
    for j in range(W):
        if city[i][j]<0:
            city[i][j]="-1"
        else:
            city[i][j]=str(city[i][j])

for c in city:
    print(" ".join(c))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ans = []
for _ in range(h):
    data = [i for i in input()]
    cnt = 1
    for i in range(w-1):
        if (data[i] == "c" and data[i+1] == ".") or (type(data[i]) == int and data[i+1] == "."):
            data[i+1] = cnt
            cnt += 1
        else:
            cnt = 1

    data = ["-1" if d == "." else d for d in data]
    data = ["0" if d == "c" else d for d in data]
    data = list(map(str, data))
    print(*data)

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
for _ in range(h):
    s = input()
    ans = []
    for i in range(len(s)):
        if s[i] == 'c':
            ans.append(0)
        elif i == 0:
            ans.append(-1)
        else:
            for j in range(1,i+1):
                if s[i-j] == 'c':
                    ans.append(j)
                    break
                if j == i:
                    ans.append(-1)
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
#C問題
H,W = map(int,input().split())
G = [list(str(input())) for i in range(H)]
ans = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    g = G[i]
    cnow = -1
    for j in range(W):
        if g[j] == "c":
            cnow = j
            ans[i][j] = 0
        else:
            if cnow == -1:
                ans[i][j] = -1
            else:
                ans[i][j] = j-cnow
                
for a in ans:
    print(*a)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
c=[list(input()) for _ in range(h)]
ans=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if c[i][j]=='.':
            if c[i][:j].count('c')==0:
                ans[i][j]=-1
            else:
                for k in range(1,j+1):
                    if c[i][j-k]=='c':
                        ans[i][j]=k
                        break
for i in ans:
    print(*i)

Submission status: Accepted

Solution code:
H, W = map(int, raw_input().split())
sky = []
for i in range(0, H):
	sky.append(raw_input())
answer = []
for i in range(0, H):
	lst = []
	tmp = -1
	for j in range(0, W):
		if sky[i][j] == 'c':
			tmp = 0
		elif tmp != -1:
			tmp += 1
		lst.append(tmp)
	answer.append(lst)
for i in range(0, H):
	ans = str(answer[i][0])
	for j in range(1, W):
		ans = ans + ' ' + str(answer[i][j])
	print ans

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
town=[]
for i in range(n):
    weather=input()
    c=-1
    t_c=[]
    for j in range(m):
        if weather[j]=="c":c=0
        t_c.append(c)
        if c>-1:c+=1
    town.append(t_c)
for i in town:print(' '.join(map(str,i)))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())

for _ in range(h):
    cloud = list(input())
    cnt = -1
    flag = False
    ans = []
    for c in cloud:
        if c == "c":
            flag = True
            cnt = 0
        elif flag:
            cnt += 1
        ans.append(cnt)
    print(' '. join(str(a) for a in ans))

Submission status: WA: Presentation Error

Solution code:
h,w=map(int,input().split())
while h:
    h-=1
    n=input()
    c=-1
    for i in range(w):
        if n[i]=='c':c=0
        print(c,end=" ")
        if c!=-1:c+=1
    print()

Submission status: WA: Presentation Error

Solution code:
h,_=map(int,input().split())
while h:
    h-=1
    c=-1
    for x in input():
        if x=='c':c=0
        print(c,end=' ')
        if c!=-1:c+=1
    print()

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
h, w = map(int, input().split())
cloud = [[i for i in input()] for i in range(h)]
flag = 0 #1?????¨????????????
cnt = 0 
for i in range(h):
    for j in range(w):
        if flag==0 and cloud[i][j]=='.':
            print(-1, end=' ')
        elif cloud[i][j]=='c':
            print(0, end=' ')
            flag = 1
            cnt = 0
        else:
            cnt += 1
            print(cnt, end=' ')
    print()
    cnt = 0
    flag = 0

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
h, w = map(int, input().split())
cloud = [[i for i in input()] for i in range(h)]
flag = 0 #1?????¨????????????
cnt = 0 
for i in range(h):
    for j in range(w):
        if flag==0 and cloud[i][j]=='.':
            print(-1, end='')
        elif cloud[i][j]=='c':
            print(0, end='')
            flag = 1
            cnt = 0
        else:
            cnt += 1
            print(cnt, end='')
    print()
    cnt = 0
    flag = 0

Submission status: WA: Presentation Error

Solution code:
# coding: utf-8
h, w = map(int, input().split())
cloud = [[i for i in input()] for i in range(h)]
flag = 0 #1?????¨????????????
cnt = 0 
for i in range(h):
    for j in range(w):
        if flag==0 and cloud[i][j]=='.':
            print(-1, end=' ')
        elif cloud[i][j]=='c':
            print(0, end=' ')
            flag = 1
            cnt = 0
        else:
            cnt += 1
            print(cnt, end=' ')
    print()
    cnt = 0
    flag = 0
print()