結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー motimoti
提出日時 2015-07-13 00:34:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,048 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 80,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 14:37:30
合計ジャッジ時間 1,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:25: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       int nx = x+dx[i], ny = y+dy[i];
                         ^~
main.cpp:31:11: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       int nx = x+dx[i], ny = y+dy[i];
           ^~

ソースコード

diff #

#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;
}
0