結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー GuestGuest
提出日時 2018-02-07 21:09:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,829 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 57,160 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:48:38
合計ジャッジ時間 1,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;

int main() {
	int puzzle[4][4];
	int answer[4][4];
	int i, j, m, n;
	bool result = true;
	int x = 1;

	//puzzleを初期化
	for (int i = 0; i < 4;i++) {
		for (int j = 0; j < 4;j++) {
			puzzle[i][j] = x;
			x++;
		}
	}
	puzzle[3][3] = 0;

	//目標を入力
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> answer[i][j];
		}
	}

	//目標との照合
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			for (m = 0; m < 4; m++) {
				for (n = 0; n < 4; n++) {
					switch (result) {
					case true:
						if (puzzle[i][j] == answer[m][n] && puzzle[i][j] != 0) {
							if (abs(i - m) > 1 || abs(j - n) > 1 || (abs(i - m) == 1 && abs(j - n) == 1)) {
								result = false;
							}
							else {
								if (n != 0) {
									if (answer[m][n - 1] - answer[m][n] == 1) {
										result = false;
									}
									else if (answer[m][n] == puzzle[m][n - 1] && answer[m][n - 1] == puzzle[m][n] && answer[m][n] != 0 && answer[m][n - 1] != 0) {
										result = false;
									}
								}
								if (m != 0) {
									if (answer[m][n] == puzzle[m - 1][n] && answer[m - 1][n] == puzzle[m][n] && answer[m][n] != 0 && answer[m - 1][n] != 0) {
										result = false;
									}
								}
								if (n != 4) {
									if (answer[m][n] == puzzle[m][n + 1] && answer[m][n + 1] == puzzle[m][n] && answer[m][n] != 0 && answer[m][n + 1] != 0) {
										result = false;
									}
								}
								if (m != 4) {
									if (answer[m][n] == puzzle[m + 1][n] && answer[m + 1][n] == puzzle[m][n] && answer[m][n] != 0 && answer[m + 1][n] != 0) {
										result = false;
									}
								}
							}
						}
						break;

					case false:
						break;
					}
				}
			}
		}
	}

	if (result == true) 
		cout << "Yes";
	if (result == false) 
		cout << "No";
}
0