結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  taba | 
| 提出日時 | 2017-05-20 04:12:23 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 921 bytes | 
| コンパイル時間 | 710 ms | 
| コンパイル使用メモリ | 110,320 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-18 23:31:57 | 
| 合計ジャッジ時間 | 1,302 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:21: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |         bool ret=dfs(t,0,x,y);
      |                  ~~~^~~~~~~~~
main.cpp:47:21: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
            
            ソースコード
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <random>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <utility>
#include <regex>
#include <tuple>
#include <map>
#include <set>
#include <iostream>
using namespace std;
uint64_t dfs(array<int,16> b,uint16_t m,char x,char y){
	if(is_sorted(b.begin(),b.end()-1)&&b[15]==0){
		return true;
	}
	bool ret=false;
	int d[][2]={{1,0},{-1,0},{0,1},{0,-1}};
	for(int i=0;i<4&&!ret;i++){
		char nx=x+d[i][0],ny=y+d[i][1];
		if(0<=nx&&nx<4&&0<=ny&&ny<4&&(m&(1<<b[ny*4+nx]))==0){
			array<int,16> nb(b);
			uint16_t nm=m|(1<<nb[ny*4+nx]);
			swap(nb[y*4+x],nb[ny*4+nx]);
			ret=dfs(nb,nm,nx,ny);
		}
	}
	return ret;
}
int main(){
	array<int,16> t;
	char x,y;
	for(int i=0;i<16;i++){
		-scanf("%d",&t[i]);
		if(t[i]==0){
			y=i>>2;
			x=i&3;
		}
	}
	bool ret=dfs(t,0,x,y);
	puts(ret?"Yes":"No");
	return 0;
}
            
            
            
        