結果

問題 No.307 最近色塗る問題多くない?
ユーザー koyumeishikoyumeishi
提出日時 2015-11-27 05:20:08
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,452 ms / 4,000 ms
コード長 1,273 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 77,468 KB
実行使用メモリ 110,548 KB
最終ジャッジ日時 2023-08-14 03:40:47
合計ジャッジ時間 12,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,768 KB
testcase_01 AC 70 ms
76,632 KB
testcase_02 AC 71 ms
76,724 KB
testcase_03 AC 71 ms
76,588 KB
testcase_04 AC 97 ms
79,408 KB
testcase_05 AC 77 ms
79,528 KB
testcase_06 AC 81 ms
79,416 KB
testcase_07 AC 126 ms
80,320 KB
testcase_08 AC 193 ms
82,040 KB
testcase_09 AC 139 ms
81,052 KB
testcase_10 AC 115 ms
80,760 KB
testcase_11 AC 122 ms
80,604 KB
testcase_12 AC 71 ms
76,732 KB
testcase_13 AC 127 ms
80,420 KB
testcase_14 AC 105 ms
80,312 KB
testcase_15 AC 99 ms
79,452 KB
testcase_16 AC 100 ms
79,504 KB
testcase_17 AC 158 ms
80,352 KB
testcase_18 AC 280 ms
82,960 KB
testcase_19 AC 237 ms
82,372 KB
testcase_20 AC 82 ms
79,496 KB
testcase_21 AC 218 ms
81,180 KB
testcase_22 AC 202 ms
81,936 KB
testcase_23 AC 1,289 ms
106,064 KB
testcase_24 AC 461 ms
84,616 KB
testcase_25 AC 624 ms
89,928 KB
testcase_26 AC 1,246 ms
109,364 KB
testcase_27 AC 133 ms
81,400 KB
testcase_28 AC 229 ms
83,228 KB
testcase_29 AC 115 ms
79,980 KB
testcase_30 AC 1,452 ms
110,548 KB
testcase_31 AC 177 ms
82,136 KB
testcase_32 AC 148 ms
81,160 KB
testcase_33 AC 119 ms
80,252 KB
testcase_34 AC 129 ms
81,148 KB
testcase_35 AC 142 ms
81,164 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()) )

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

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

	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

	visit[start] = turn

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

		x = pos % w
		y = pos // w
		
		ret += 1;
		a[y][x] = color

		for k in xrange(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 (visit[next_pos] == turn) or (a[yy][xx] == color) :
				continue

			visit[next_pos] = turn
			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, i)
	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 , "ms"
0