結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-18 21:38:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,383 bytes
コンパイル時間 4,525 ms
コンパイル使用メモリ 79,800 KB
実行使用メモリ 41,692 KB
最終ジャッジ日時 2024-04-18 02:55:56
合計ジャッジ時間 7,758 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
41,072 KB
testcase_01 AC 134 ms
41,692 KB
testcase_02 AC 140 ms
41,556 KB
testcase_03 AC 122 ms
40,220 KB
testcase_04 AC 135 ms
41,244 KB
testcase_05 AC 141 ms
41,352 KB
testcase_06 AC 138 ms
41,288 KB
testcase_07 AC 141 ms
41,320 KB
testcase_08 AC 138 ms
41,396 KB
testcase_09 AC 140 ms
41,372 KB
testcase_10 AC 143 ms
41,344 KB
testcase_11 AC 127 ms
40,352 KB
testcase_12 AC 138 ms
41,156 KB
testcase_13 AC 123 ms
40,060 KB
testcase_14 AC 140 ms
41,244 KB
testcase_15 AC 138 ms
41,244 KB
testcase_16 AC 141 ms
41,324 KB
testcase_17 AC 136 ms
41,672 KB
testcase_18 AC 139 ms
41,380 KB
testcase_19 AC 140 ms
41,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise95{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    ArrayList<Integer> a = new ArrayList<Integer>();
    for(int i = 1; i < 16; i++){
      a.add(i);
    }
    a.add(0);
    ArrayList<Integer> q = new ArrayList<Integer>();
    for(int i = 0; i < 16; i++){
      q.add(sc.nextInt());
    }
    while(q.indexOf(0) != 15){
      int x = q.indexOf(0);
      if (x > 3) {
        if(q.get(x - 4) == a.get(x)){
          int y = q.get(x - 4);
          q.set(x - 4, q.get(x));
          q.set(x, y);
          continue;
        }
      }

      if(x % 4 != 3){
        if(q.get(x + 1) == a.get(x)){
          int y = q.get(x + 1);
          q.set(x + 1, q.get(x));
          q.set(x, y);
          continue;
        }
      }

      if(x < 12){
        if(q.get(x + 4) == a.get(x)){
          int y = q.get(x + 4);
          q.set(x + 4, q.get(x));
          q.set(x, y);
          continue;
        }
      }

      if (x % 4 != 0) {
        if(q.get(x - 1) == a.get(x)){
          int y = q.get(x - 1);
          q.set(x - 1, q.get(x));
          q.set(x, y);
          continue;
        }
      }

      break;
    }

    Integer[] ad = (Integer[])a.toArray(new Integer[16]);
    Integer[] qd = (Integer[])q.toArray(new Integer[16]);
    System.out.println((Arrays.equals(ad, qd))? "Yes" : "No");
  }
}
0