結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 05:51:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,267 ms / 4,000 ms
コード長 1,192 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 104,388 KB
最終ジャッジ日時 2024-05-01 16:33:20
合計ジャッジ時間 8,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,352 KB
testcase_01 AC 36 ms
51,968 KB
testcase_02 AC 36 ms
52,096 KB
testcase_03 AC 36 ms
52,096 KB
testcase_04 AC 49 ms
63,744 KB
testcase_05 AC 45 ms
59,648 KB
testcase_06 AC 42 ms
60,160 KB
testcase_07 AC 86 ms
76,544 KB
testcase_08 AC 138 ms
78,032 KB
testcase_09 AC 97 ms
76,928 KB
testcase_10 AC 81 ms
76,288 KB
testcase_11 AC 87 ms
76,544 KB
testcase_12 AC 36 ms
52,352 KB
testcase_13 AC 92 ms
76,288 KB
testcase_14 AC 59 ms
69,588 KB
testcase_15 AC 55 ms
72,064 KB
testcase_16 AC 59 ms
71,936 KB
testcase_17 AC 102 ms
77,056 KB
testcase_18 AC 213 ms
79,188 KB
testcase_19 AC 181 ms
78,080 KB
testcase_20 AC 44 ms
61,824 KB
testcase_21 AC 122 ms
77,184 KB
testcase_22 AC 146 ms
77,952 KB
testcase_23 AC 1,125 ms
100,600 KB
testcase_24 AC 352 ms
80,384 KB
testcase_25 AC 516 ms
85,684 KB
testcase_26 AC 1,057 ms
103,208 KB
testcase_27 AC 103 ms
77,312 KB
testcase_28 AC 178 ms
79,488 KB
testcase_29 AC 80 ms
76,416 KB
testcase_30 AC 1,267 ms
104,388 KB
testcase_31 AC 140 ms
77,440 KB
testcase_32 AC 114 ms
77,364 KB
testcase_33 AC 78 ms
76,624 KB
testcase_34 AC 95 ms
77,184 KB
testcase_35 AC 101 ms
77,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#import time
#start = time.clock()

h,w = map(int, input().split())

a = []
for i in range(h):
	a.append( list(map(int, input().split())) )

q_ = [None] * (h*w)
ptr = 0

def bfs (start, color) :
	global a
	global q_
	global ptr

	if a[start // w][start % w] == color :
		return 0

	dx = [0,0,1,-1]
	dy = [1,-1,0,0]

	ret = 0
	q_[ptr] = start
	ptr += 1

	a[start // w][start % w] = color

	while ptr != 0 :
		pos = q_[ptr-1]
		ptr -= 1

		x = pos % w
		y = pos // w
		
		ret += 1;

		for k in range(4) :
			xx = x + dx[k]
			yy = y + dy[k]
			next_pos = yy * w + xx
			if xx<0 or xx >= w or yy<0 or yy>=h :
				continue
			if (a[yy][xx] == color) :
				continue

			a[yy][xx] = color
			q_[ptr] = next_pos
			ptr += 1

	return ret;


filled = False;
last = -1;
q = int(input())

for i in range(q):
	r,c,x = map(int, input().split())
	r = r-1;
	c = c-1;
	last = x;
	if (a[r][c] == x or filled == True) :
		continue

	cnt = bfs(r * w + c, x)
	if (w*h == cnt) : 
		filled = True

#import sys
#print >> sys.stderr, filled

if (filled == True) :
	for i in range(h):
		a[i] = str(last) * w

for i in range(h):
	print ( ' '.join(map(str, a[i])) )



#print >> sys.stderr, time.clock() - start , "sec"
0