結果

問題 No.179 塗り分け
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-31 07:08:59
言語 Ruby
(3.2.2)
結果
AC  
実行時間 2,018 ms / 3,000 ms
コード長 727 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 23,844 KB
最終ジャッジ日時 2023-09-30 21:00:38
合計ジャッジ時間 26,164 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,148 KB
testcase_01 AC 82 ms
15,156 KB
testcase_02 AC 79 ms
15,084 KB
testcase_03 AC 81 ms
15,156 KB
testcase_04 AC 80 ms
15,344 KB
testcase_05 AC 223 ms
19,252 KB
testcase_06 AC 81 ms
15,136 KB
testcase_07 AC 1,408 ms
23,492 KB
testcase_08 AC 1,398 ms
23,612 KB
testcase_09 AC 1,440 ms
23,420 KB
testcase_10 AC 82 ms
15,372 KB
testcase_11 AC 81 ms
15,180 KB
testcase_12 AC 1,261 ms
23,844 KB
testcase_13 AC 82 ms
15,484 KB
testcase_14 AC 82 ms
15,468 KB
testcase_15 AC 77 ms
15,296 KB
testcase_16 AC 78 ms
15,300 KB
testcase_17 AC 79 ms
15,308 KB
testcase_18 AC 110 ms
19,100 KB
testcase_19 AC 108 ms
19,056 KB
testcase_20 AC 1,327 ms
23,324 KB
testcase_21 AC 1,587 ms
23,396 KB
testcase_22 AC 2,018 ms
23,608 KB
testcase_23 AC 81 ms
15,224 KB
testcase_24 AC 1,455 ms
23,288 KB
testcase_25 AC 93 ms
17,140 KB
testcase_26 AC 290 ms
23,548 KB
testcase_27 AC 1,489 ms
23,556 KB
testcase_28 AC 157 ms
23,504 KB
testcase_29 AC 1,510 ms
23,612 KB
testcase_30 AC 667 ms
23,368 KB
testcase_31 AC 1,547 ms
23,404 KB
testcase_32 AC 466 ms
23,528 KB
testcase_33 AC 1,505 ms
23,348 KB
testcase_34 AC 346 ms
23,520 KB
testcase_35 AC 1,509 ms
23,596 KB
testcase_36 AC 79 ms
15,044 KB
testcase_37 AC 79 ms
15,088 KB
testcase_38 AC 79 ms
15,296 KB
testcase_39 AC 79 ms
15,176 KB
testcase_40 AC 78 ms
15,128 KB
testcase_41 AC 79 ms
15,176 KB
testcase_42 AC 79 ms
15,348 KB
testcase_43 AC 110 ms
17,108 KB
testcase_44 AC 248 ms
19,396 KB
testcase_45 AC 86 ms
15,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(ar,dx,dy,h,w,c)
	
	arr= Marshal.load(Marshal.dump(ar))

	return false if c==0
	h.times{|y|
		
		w.times{|x|
			y1=y+dy
			x1=x+dx
			if arr[y][x]==1
				return false if x1<0 || x1>=w || y1<0 || y1>=h
				arr[y1][x1]-=1
				c-=2
			end
			next if x1<0 || x1>=w ||  y1<0 || y1>=h
			return false if arr[y1][x1]<0
		}
	}
	return c==0
end

h,w=gets.split.map{|e| e.to_i}
m=[]
h.times{
	m<<gets.chomp
}


arr=Array.new(h).map{Array.new(w,0)}
c=0
i=0
m.each{|e|
	j=0
	e.chars{|e2|
		if e2=="#"
			arr[i][j]=1
			c+=1
		else
			arr[i][j]=0
		end
		j+=1
	}
	i+=1
}

ok=false
h.times{|dy|
	w.times{|dx|
		if dy+dx!=0
			ok=ok||f(arr,dx,dy,h,w,c)
			ok=ok||f(arr,-dx,dy,h,w,c)
		end
	}
}
if ok==true
	puts "YES"
else
	puts "NO"
end
0