結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー ぴろずぴろず
提出日時 2015-06-19 22:33:33
言語 Java19
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 79,208 KB
実行使用メモリ 56,080 KB
最終ジャッジ日時 2023-09-21 09:58:45
合計ジャッジ時間 5,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,796 KB
testcase_01 AC 128 ms
55,736 KB
testcase_02 AC 127 ms
55,756 KB
testcase_03 AC 127 ms
55,680 KB
testcase_04 AC 126 ms
55,640 KB
testcase_05 AC 127 ms
55,624 KB
testcase_06 AC 127 ms
55,440 KB
testcase_07 AC 127 ms
55,748 KB
testcase_08 AC 127 ms
55,812 KB
testcase_09 AC 127 ms
55,588 KB
testcase_10 AC 126 ms
56,080 KB
testcase_11 AC 127 ms
55,560 KB
testcase_12 AC 126 ms
55,760 KB
testcase_13 AC 126 ms
55,732 KB
testcase_14 AC 127 ms
56,068 KB
testcase_15 AC 127 ms
55,976 KB
testcase_16 AC 127 ms
55,672 KB
testcase_17 AC 128 ms
55,524 KB
testcase_18 AC 127 ms
56,024 KB
testcase_19 AC 128 ms
56,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no228;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] di = {0,-1,0,1};
		int[] dj = {1,0,-1,0};
		Scanner sc = new Scanner(System.in);
		int[][] map = new int[4][4];
		boolean[][] moved = new boolean[4][4];
		int bi = 0, bj = 0;
		for(int i=0;i<4;i++) {
			for(int j=0;j<4;j++) {
				map[i][j] = sc.nextInt();
				if (map[i][j] == 0) {
					bi = i;
					bj = j;
				}
			}
		}
		while(true) {
			boolean update = false;
			for(int k=0;k<4;k++) {
				int ni = bi + di[k];
				int nj = bj + dj[k];
				if (ni < 0 || ni >= 4 || nj < 0 || nj >= 4) {
					continue;
				}
				if (!moved[ni][nj] && map[ni][nj] == (bi * 4 + bj + 1)) {
					map[bi][bj] = bi * 4 + bj + 1;
					map[ni][nj] = 0;
					moved[bi][bj] = true;
					bi = ni;
					bj = nj;
					update = true;
					break;
				}
			}
			if (!update) {
				break;
			}
		}
		boolean ans = true;
		for(int i=0;i<4;i++) {
			for(int j=0;j<4;j++) {
				if (map[i][j] != (i * 4 + j + 1) % 16) {
					ans = false;
				}
			}
		}
		System.out.println(ans ? "Yes" : "No");
	}

}
0