結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー hotpepsihotpepsi
提出日時 2016-08-10 01:22:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 66,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:08:56
合計ジャッジ時間 1,554 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:38:34: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |                 } else if (y < 3 && a[y + 1][x] == g[y][x]) {
main.cpp:32:34: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |                 } else if (x < 3 && a[y][x + 1] == g[y][x]) {

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

typedef vector<int> IntVec;

int main(int argc, char *argv[]) {
	int x, y;
	IntVec g[4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0} };
	IntVec a[4];
	for (int i = 0; i < 4; ++i) {
		a[i].resize(4);
		for (int j = 0; j < 4; ++j) {
			cin >> a[i][j];
			if (a[i][j] == 0) {
				y = i, x = j;
			}
		}
	}
	bool ans = false;
	while (true) {
		if (a[0] == g[0] && a[1] == g[1] && a[2] == g[2] && a[3] == g[3]) {
			ans = true;
			break;
		}
		if (x > 0 && a[y][x - 1] == g[y][x]) {
			swap(a[y][x], a[y][x - 1]);
			--x;
		} else if (x < 3 && a[y][x + 1] == g[y][x]) {
			swap(a[y][x], a[y][x + 1]);
			++x;
		} else if (y > 0 && a[y - 1][x] == g[y][x]) {
			swap(a[y][x], a[y - 1][x]);
			--y;
		} else if (y < 3 && a[y + 1][x] == g[y][x]) {
			swap(a[y][x], a[y + 1][x]);
			++y;
		} else {
			break;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}
0