結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー KKT89KKT89
提出日時 2020-10-12 06:34:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 818 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 198,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:34:25
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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;
 		}
	}
	if(ok)printf("Yes\n");
	else printf("No\n");
}
0