結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 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]) {
							if ((abs(i - m) > 1 && abs(j - n) > 1) || (abs(i - m) == 1 && abs(j - n) == 1)) {
								result = false;
							}
							else if(n != 3 && m != 3) {
								if (answer[m - 1][n - 1] - answer[m][n] == -1) {
									result = false;
								}
							}
						}
						break;
					case false:
						break;
					}
				}
			}
		}
	}

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