結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 10:21:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 13,804 KB
最終ジャッジ日時 2023-10-11 23:10:34
合計ジャッジ時間 12,320 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,408 KB
testcase_01 AC 16 ms
8,216 KB
testcase_02 AC 16 ms
8,268 KB
testcase_03 AC 16 ms
8,300 KB
testcase_04 AC 19 ms
8,340 KB
testcase_05 AC 16 ms
8,304 KB
testcase_06 AC 16 ms
8,200 KB
testcase_07 AC 76 ms
8,084 KB
testcase_08 AC 492 ms
9,448 KB
testcase_09 AC 182 ms
8,716 KB
testcase_10 AC 32 ms
8,348 KB
testcase_11 AC 54 ms
8,608 KB
testcase_12 AC 17 ms
8,184 KB
testcase_13 AC 145 ms
8,360 KB
testcase_14 AC 32 ms
7,972 KB
testcase_15 AC 44 ms
8,012 KB
testcase_16 AC 44 ms
8,280 KB
testcase_17 AC 433 ms
8,836 KB
testcase_18 AC 1,419 ms
9,060 KB
testcase_19 AC 1,166 ms
8,992 KB
testcase_20 AC 18 ms
8,424 KB
testcase_21 AC 849 ms
8,960 KB
testcase_22 AC 695 ms
9,244 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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