結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-11 22:02:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 868 bytes | 
| コンパイル時間 | 1,143 ms | 
| コンパイル使用メモリ | 158,200 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 21:03:14 | 
| 合計ジャッジ時間 | 1,921 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int a[4][4];
int dy[] = {-1, 0, 0, 1};
int dx[] = {0, -1, 1, 0};
int y, x;
int main(void) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> a[i][j];
      if (a[i][j]) continue;
      a[i][j] = 16;
      y = i, x = j;
    }
  }
  while (true) {
    bool update = false;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny >= 0 && ny < 4 && nx >= 0 && nx < 4) {
        if (a[ny][nx] == y * 4 + x + 1) {
          swap(a[y][x], a[ny][nx]);
          y = ny; x = nx;
          update = true;
          break;
        }
      }
    }
    if (!update) break;
  }
  bool yes = true;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      yes &= (a[i][j] == i * 4 + j + 1);
    }
  }
  cout << (yes ? "Yes" : "No") << endl;
  return 0;
}
            
            
            
        