結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 05:41:13
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,491 ms / 4,000 ms
コード長 1,197 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 77,480 KB
実行使用メモリ 110,660 KB
最終ジャッジ日時 2023-08-14 03:42:36
合計ジャッジ時間 12,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
76,372 KB
testcase_01 AC 73 ms
76,120 KB
testcase_02 AC 76 ms
76,148 KB
testcase_03 AC 74 ms
76,184 KB
testcase_04 AC 99 ms
78,976 KB
testcase_05 AC 82 ms
79,236 KB
testcase_06 AC 84 ms
79,120 KB
testcase_07 AC 125 ms
79,892 KB
testcase_08 AC 183 ms
81,556 KB
testcase_09 AC 129 ms
80,392 KB
testcase_10 AC 114 ms
79,856 KB
testcase_11 AC 121 ms
80,148 KB
testcase_12 AC 76 ms
76,444 KB
testcase_13 AC 132 ms
80,084 KB
testcase_14 AC 97 ms
79,256 KB
testcase_15 AC 94 ms
79,136 KB
testcase_16 AC 95 ms
79,420 KB
testcase_17 AC 148 ms
79,912 KB
testcase_18 AC 269 ms
82,524 KB
testcase_19 AC 227 ms
81,840 KB
testcase_20 AC 87 ms
79,144 KB
testcase_21 AC 167 ms
80,312 KB
testcase_22 AC 183 ms
81,228 KB
testcase_23 AC 1,318 ms
105,556 KB
testcase_24 AC 432 ms
84,364 KB
testcase_25 AC 664 ms
89,708 KB
testcase_26 AC 1,259 ms
108,928 KB
testcase_27 AC 123 ms
80,500 KB
testcase_28 AC 206 ms
82,356 KB
testcase_29 AC 113 ms
79,848 KB
testcase_30 AC 1,491 ms
110,660 KB
testcase_31 AC 168 ms
81,308 KB
testcase_32 AC 143 ms
80,996 KB
testcase_33 AC 110 ms
80,044 KB
testcase_34 AC 124 ms
80,132 KB
testcase_35 AC 133 ms
80,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#import time
#start = time.clock()

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

a = []
for i in xrange(h):
	a.append( map(int, raw_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 = input()

for i in xrange(q):
	r,c,x = map(int, raw_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 xrange(h):
		a[i] = str(last) * w

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



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