結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー nCk_cvnCk_cv
提出日時 2016-02-17 19:10:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 1,211 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 78,024 KB
実行使用メモリ 57,768 KB
最終ジャッジ日時 2023-10-22 06:16:09
合計ジャッジ時間 6,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,500 KB
testcase_01 AC 138 ms
57,768 KB
testcase_02 AC 136 ms
57,508 KB
testcase_03 AC 135 ms
57,204 KB
testcase_04 AC 137 ms
57,508 KB
testcase_05 AC 133 ms
55,488 KB
testcase_06 AC 135 ms
57,504 KB
testcase_07 AC 134 ms
57,472 KB
testcase_08 AC 137 ms
57,232 KB
testcase_09 AC 134 ms
57,264 KB
testcase_10 AC 134 ms
57,436 KB
testcase_11 AC 135 ms
57,600 KB
testcase_12 AC 134 ms
57,472 KB
testcase_13 AC 136 ms
57,512 KB
testcase_14 AC 138 ms
57,524 KB
testcase_15 AC 140 ms
57,532 KB
testcase_16 AC 137 ms
57,504 KB
testcase_17 AC 138 ms
57,736 KB
testcase_18 AC 137 ms
57,496 KB
testcase_19 AC 133 ms
57,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.awt.geom.*;
import java.io.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] map = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
		int[][] target = new int[4][4];
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 4; j++) {
				target[i][j] = sc.nextInt();
			}
		}
		int x = 3;
		int y = 3;
		boolean ok = true;
		boolean[] moved = new boolean[16];
		while(true) {
			boolean check = true;
			for(int i = 0; i < 4; i++) {
				for(int j = 0; j < 4; j++) {
					if(target[i][j] != map[i][j]) check = false;
				}
			}
			if(check) break;
			int[] vx = {1,0,-1,0};
			int[] vy = {0,1,0,-1};
			check = true;
			for(int i = 0; i < 4; i++) {
				int tmpx = vx[i] + x;
				int tmpy = vy[i] + y;
				if(tmpx < 0 || tmpy < 0 || tmpx > 3 || tmpy > 3) continue;
				if(target[y][x] == map[tmpy][tmpx] && !moved[target[y][x]]) {
					moved[target[y][x]] = true;
					map[tmpy][tmpx] = 0;
					map[y][x] = target[y][x];
					check = false;
					x = tmpx;
					y = tmpy;
					break;
				}
			}
			if(check) {
				ok = false;
				break;
			}
		}
		if(ok) System.out.println("Yes");
		else System.out.println("No");
		
 	}
}
0