結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー nola_suznola_suz
提出日時 2015-06-21 13:40:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 942 bytes
コンパイル時間 1,375 ms
コンパイル使用メモリ 148,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 22:37:48
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
bool check(int a,int b){
	if(0<=a&&a<4&&0<=b&&b<4) return true;
	return false;
}
int main(){
	vector<vector<int>> vv(4,vector<int>(4));
	rep(i,4){
		rep(j,4){
			vv[i][j]=i*4+j+1;
		}
	}
	vv[3][3]=0;
	vector<vector<int>> ww=vv;
	rep(i,4){
		rep(j,4){
			cin>>ww[i][j];
		}
	}
	bool ok=true;
	int x=3;
	int y=3;
	int dd[]={1,0,-1,0,1};
	// int cnt=0;
	while(ok){
		// cout<<x<<" "<<y<<endl;
		if(ww[x][y]==vv[x][y]) break;
		rep(i,4){
			int xx=x+dd[i];
			int yy=y+dd[i+1];
			if(check(xx,yy)&&vv[xx][yy]==ww[x][y]){
				swap(vv[x][y],vv[xx][yy]);
				x=xx;
				y=yy;
				// cout<<x<<" "<<y<<" "<<xx<<" "<<yy<<endl;
				break;
			}
			if(i==3) ok=false;
		}
		// if(++cnt==100) break;
	}
	rep(i,4){
		rep(j,4){
			if(ww[i][j]!=vv[i][j]) ok=false;
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}
0