結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー 41Toame41Toame
提出日時 2018-09-05 18:30:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,292 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 150,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 20:02:38
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:8: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    int yy = y + dy[i];
        ^~
main.cpp:30:8: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    int xx = x + dx[i];
        ^~

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<vector<int>> t = { { 1,2,3,4 },{ 5,6,7,8 },{ 9,10,11,12 },{ 13,14,15,0 } };
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };
int main(void)
{
	vector<vector<int>> a(4, vector<int>(4));
	int x, y;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> a[i][j];
			if (a[i][j] == 0) x = i, y = j;
		}
	}
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0; i < 4; i++) {
			int xx = x + dx[i];
			int yy = y + dy[i];
			if (xx < 0 or xx >= 4 or yy < 0 or yy >= 4) continue;
			if (a[xx][yy] == t[x][y]) {
				swap(a[xx][yy], a[x][y]);
				x = xx, y = yy;
				flag = true;
				break;
			}
			//cout << "---------" << endl;
			//rep(i, 4) {
			//	rep(j, 4) {
			//		cout << a[i][j] << " ";
			//	}
			//	cout << endl;
			//}
		}
	}
	if (t == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;


    return 0;
}
0