結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  zaichu | 
| 提出日時 | 2016-01-17 22:04:13 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 722 bytes | 
| コンパイル時間 | 1,358 ms | 
| コンパイル使用メモリ | 164,840 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-19 20:21:12 | 
| 合計ジャッジ時間 | 2,030 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:29: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   22 |                         int yy = y + dy[i];
      |                             ^~
main.cpp:21:29: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |                         int xx = x + dx[i];
      |                             ^~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
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(){
	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 << (t == a ? "Yes" : "No") << endl;
	return 0;
}
            
            
            
        