結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー KKT89KKT89
提出日時 2020-10-12 06:33:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 197,784 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:34:22
合計ジャッジ時間 2,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int a[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
int b[4][4];
int c[4][4];

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			cin >> b[i][j];
			c[i][j]=0;
		}
	}
	int zx=3,zy=3;
	while(1){
		bool f=false;
		for(int i=0;i<4;i++){
			int nx=zx+dx[i],ny=zy+dy[i];
			if(0<=nx and nx<4 and 0<=ny and ny<4){
				if(c[nx][ny])continue;
				if(a[nx][ny]==b[zx][zy]){
					swap(a[nx][ny],a[zx][zy]);
					zx=nx; zy=ny;
					f=true;
					c[nx][ny]=true;
				}
			}
		}
		if(!f)break;
	}
	bool ok=true;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(a[i][j]!=b[i][j])ok=false;
 		}
 		cout << endl;
	}
	if(ok)printf("Yes\n");
	else printf("No\n");
}
0