結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー ldsybldsyb
提出日時 2017-06-21 23:52:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 68,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 10:04:13
合計ジャッジ時間 1,408 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:37:20: warning: 'd' may be used uninitialized [-Wmaybe-uninitialized]
   37 |         cout << (d % 2 == count % 2 ? "Yes" : "No") << endl;
      |                  ~~^~~
main.cpp:9:47: note: 'd' was declared here
    9 |         int a[4][4], dd[] = {0, 1, 0, -1, 0}, d;
      |                                               ^

ソースコード

diff #

#include <iostream>
using namespace std;

bool inside(int a, int b, int alim, int blim){
	return 0 <= a && a < alim && 0 <= b && b < blim;
}

int main(){
	int a[4][4], dd[] = {0, 1, 0, -1, 0}, d;
	for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++){
		cin >> a[i][j];
		bool f = a[i][j] == (4 * i + j + 1) % 16;
		for(int k = 0; k < 4; k++){
			int ni = i + dd[k], nj = j + dd[k + 1];
			if(inside(ni, nj, 4, 4)) f |= a[i][j] == (4 * ni + nj + 1) % 16;
		}
		if(!f){
			cerr << i << ' ' << j << endl;
			cout << "No" << endl;
			return 0;
		}
		if(a[i][j] == 0) d = 3 - i + 3 - j;
	}
	int count = 0;
	for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++){
		int p = (4 * i + j + 1) % 16;
		if(a[i][j] == p) continue;
		for(int k = 0; k < 4; k++){
			int ni = i + dd[k], nj = j + dd[k + 1];
			if(inside(ni, nj, 4, 4) && a[ni][nj] == p){
				swap(a[i][j], a[ni][nj]);
				count++;
				break;
			}
		}
	}
	cout << (d % 2 == count % 2 ? "Yes" : "No") << endl;
}
0