結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー ktshunktshun
提出日時 2015-06-25 13:45:11
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,236 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 6,760 KB
実行使用メモリ 6,048 KB
最終ジャッジ日時 2023-09-22 00:37:49
合計ジャッジ時間 1,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,864 KB
testcase_01 AC 12 ms
6,044 KB
testcase_02 AC 12 ms
6,044 KB
testcase_03 AC 11 ms
5,892 KB
testcase_04 AC 12 ms
5,848 KB
testcase_05 AC 12 ms
5,832 KB
testcase_06 AC 12 ms
6,028 KB
testcase_07 AC 11 ms
5,864 KB
testcase_08 AC 11 ms
6,032 KB
testcase_09 AC 12 ms
5,820 KB
testcase_10 AC 11 ms
5,936 KB
testcase_11 AC 12 ms
5,856 KB
testcase_12 AC 11 ms
5,856 KB
testcase_13 AC 11 ms
5,996 KB
testcase_14 AC 11 ms
5,832 KB
testcase_15 AC 12 ms
6,044 KB
testcase_16 AC 11 ms
6,048 KB
testcase_17 AC 12 ms
6,044 KB
testcase_18 AC 12 ms
5,832 KB
testcase_19 AC 12 ms
5,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding:utf-8 -*-


def solve():
	global board,ans,isMoved
	for i in xrange(4):
		if 0 in board[i]:
			y = i
			x = board[i].index(0)
	if x + 1 < 4:
		if board[y][x+1] == ans[y][x] and isMoved[y][x+1] == False:
			board[y][x],board[y][x+1] = board[y][x+1],board[y][x]
			isMoved[y][x+1] = True
			return True
	if x - 1 >= 0:
		if board[y][x-1] == ans[y][x]and isMoved[y][x-1] == False:
			board[y][x],board[y][x-1] = board[y][x-1],board[y][x]
			isMoved[y][x-1] = True
			return True
	if y + 1 < 4:
		if board[y+1][x] == ans[y][x]and isMoved[y+1][x] == False:
			board[y][x],board[y+1][x] = board[y+1][x],board[y][x]
			isMoved[y+1][x] = True
			return True
	if y - 1 >= 0:
		if board[y-1][x] == ans[y][x]and isMoved[y-1][x] == False:
			board[y][x],board[y-1][x] = board[y-1][x],board[y][x]
			isMoved[y-1][x] = True
			return True
	return False


if __name__ == "__main__":
	ans = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
	isMoved = [[False for i in xrange(4)]for i in xrange(4)]
	board = [[]for i in xrange(4)]
	for i in xrange(4):
		board[i] = map(int,raw_input().split())
	i = 0
	while board != ans and i < 16:
		if solve() == False:
			print "No"
			exit()
		i += 1
	if ans == board:
		print "Yes"
	else:
		print "No"
0