結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  moti | 
| 提出日時 | 2015-07-13 00:34:58 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,048 bytes | 
| コンパイル時間 | 661 ms | 
| コンパイル使用メモリ | 85,528 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-08 06:13:15 | 
| 合計ジャッジ時間 | 1,401 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:25: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |       int nx = x+dx[i], ny = y+dy[i];
      |                         ^~
main.cpp:31:11: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |       int nx = x+dx[i], ny = y+dy[i];
      |           ^~
            
            ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
constexpr bool inrange(int x, int y) { return 0<=x&&x<4&&0<=y&&y<4; }
int main() {
  set<int> used;
  int a[4][4], x, y;
  rep(i, 4) rep(j, 4) { cin >> a[i][j]; if(a[i][j] == 0) x = j, y = i; }
  while(1) {
    bool ok = false;
    rep(i, 4) {
      int nx = x+dx[i], ny = y+dy[i];
      if(!inrange(nx, ny)) { continue; }
      if(used.count(a[ny][nx])) { continue; }
      if(y*4+x+1 != a[ny][nx]) { continue; }
      ok = true;
      used.insert(a[ny][nx]);
      swap(a[ny][nx], a[y][x]);
      x = nx, y = ny;
    }
    if(!ok) {
      break;
    }
  }
  bool ok = true;
  rep(i, 4) rep(j, 4) {
    if(i == 3 && j == 3) { break; }
    if(i*4+j+1 != a[i][j]) { ok = false; }
  }
  cout << (ok ? "Yes\n" : "No\n");
  return 0;
}
            
            
            
        