結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー GuestGuest
提出日時 2018-02-06 21:59:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 52,316 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 13:11:16
合計ジャッジ時間 1,635 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 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 2 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 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 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;
								}
							}
						}
						break;

					case false:
						break;
					}
				}
			}
		}
	}

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