結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-11 18:52:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,114 bytes |
| コンパイル時間 | 1,859 ms |
| コンパイル使用メモリ | 77,636 KB |
| 実行使用メモリ | 54,320 KB |
| 最終ジャッジ日時 | 2024-10-04 06:33:54 |
| 合計ジャッジ時間 | 4,918 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 7 WA * 10 |
ソースコード
import java.util.*;
public class Main{
public static void main(String[] args)throws Exception{
new Main().solve();
}
static int[] dx={1,-1,0,0};
static int[] dy={0,0,1,-1};
void solve(){
Scanner sc=new Scanner(System.in);
int[][] table=new int[4][4];
int sx=-1;
int sy=-1;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
table[i][j]=sc.nextInt();
if(table[i][j]==0){
sx=j;
sy=i;
}
}
}
for(int i=0;!check(table)&&i<16;i++){
for(int j=0;j<4;j++){
int x=sx+dx[j];
int y=sy+dy[j];
if(0>x||0>y||x>=4||y>=4)continue;
if(table[y][x]==4*sy+sx+1){
int dumsXsY=table[sy][sx];
table[sy][sx]=table[y][x];
table[y][x]=dumsXsY;
tr(table);
sx=x;
sy=y;
break;
}
}
}
if(check(table)){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
boolean check(int[][] table){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(table[i][j]!=4*i+j+1&&!(i==3&&j==3&&table[i][j]==0)){
return false;
}
}
}
return true;
}
void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}