結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー y_mazuny_mazun
提出日時 2015-06-19 22:30:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 979 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 62,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 09:57:51
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <queue>
#include <cstdio>
#include <set>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

vector<vector<int> > ans(4, vector<int>(4));
vector<vector<int> > s(4, vector<int>(4));

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

bool check(int x, int y, int f){
  if(ans == s) return true;
  REP(i,4){
    const int xx = x + _dx[i];
    const int yy = y + _dy[i];
    if(ISIN(xx, yy, 4, 4)){
      const int t = s[yy][xx];

      if(f & (1 << t)){
	swap(s[y][x], s[yy][xx]);
	if(check(xx, yy, f ^ (1 << t))) return true;
	swap(s[y][x], s[yy][xx]);
      }
    }
  }
  return false;
}

int main(){
  REP(i,4) REP(j,4) ans[i][j] = getInt();
  REP(i,4) REP(j,4) s[i][j] = i * 4 + j + 1;
  s[3][3] = 0;

  puts(check(3, 3, (1 << 16) - 1) ? "Yes" : "No");
  return 0;
}
0