結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 05:51:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,253 ms / 4,000 ms
コード長 1,192 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 107,200 KB
最終ジャッジ日時 2023-08-14 03:43:25
合計ジャッジ時間 10,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,056 KB
testcase_01 AC 63 ms
71,436 KB
testcase_02 AC 62 ms
71,404 KB
testcase_03 AC 66 ms
71,504 KB
testcase_04 AC 77 ms
76,392 KB
testcase_05 AC 67 ms
76,128 KB
testcase_06 AC 67 ms
76,200 KB
testcase_07 AC 108 ms
77,748 KB
testcase_08 AC 164 ms
79,132 KB
testcase_09 AC 123 ms
78,796 KB
testcase_10 AC 104 ms
78,472 KB
testcase_11 AC 110 ms
78,720 KB
testcase_12 AC 66 ms
71,308 KB
testcase_13 AC 113 ms
77,344 KB
testcase_14 AC 84 ms
76,820 KB
testcase_15 AC 80 ms
76,440 KB
testcase_16 AC 83 ms
76,700 KB
testcase_17 AC 127 ms
77,656 KB
testcase_18 AC 231 ms
80,108 KB
testcase_19 AC 208 ms
79,372 KB
testcase_20 AC 73 ms
76,388 KB
testcase_21 AC 152 ms
78,444 KB
testcase_22 AC 167 ms
79,364 KB
testcase_23 AC 1,172 ms
101,264 KB
testcase_24 AC 385 ms
81,800 KB
testcase_25 AC 568 ms
86,828 KB
testcase_26 AC 1,078 ms
104,280 KB
testcase_27 AC 127 ms
78,288 KB
testcase_28 AC 200 ms
81,240 KB
testcase_29 AC 104 ms
77,276 KB
testcase_30 AC 1,253 ms
107,200 KB
testcase_31 AC 152 ms
80,544 KB
testcase_32 AC 133 ms
80,188 KB
testcase_33 AC 99 ms
77,880 KB
testcase_34 AC 111 ms
79,072 KB
testcase_35 AC 119 ms
79,168 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