結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-25 16:25:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,544 bytes |
| コンパイル時間 | 1,021 ms |
| コンパイル使用メモリ | 96,488 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 08:06:51 |
| 合計ジャッジ時間 | 1,784 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int main() {
vector<int> a(16);
for (int& i : a) cin >> i;
queue<pair<unordered_set<int>, vector<int>>> b;
b.emplace(unordered_set<int>(), a);
while (!b.empty()) {
int c = find(b.front().second.begin(), b.front().second.end(), 0) - b.front().second.begin(), i;
for (i = 0; i < 15; ++i) {
if (1 + i != b.front().second[i]) break;
}
if (15 == i) break;
if (3 != c % 4) {
if (!b.front().first.count(b.front().second[1 + c])) {
pair<unordered_set<int>, vector<int>> d(b.front());
swap(d.second[1 + c], d.second[c]);
d.first.insert(d.second[c]);
b.push(d);
}
}
if (3 != c / 4) {
if (!b.front().first.count(b.front().second[4 + c])) {
pair<unordered_set<int>, vector<int>> d(b.front());
swap(d.second[4 + c], d.second[c]);
d.first.insert(d.second[c]);
b.push(d);
}
}
if (c % 4) {
if (!b.front().first.count(b.front().second[c - 1])) {
pair<unordered_set<int>, vector<int>> d(b.front());
swap(d.second[c - 1], d.second[c]);
d.first.insert(d.second[c]);
b.push(d);
}
}
if (c / 4) {
if (!b.front().first.count(b.front().second[c - 4])) {
pair<unordered_set<int>, vector<int>> d(b.front());
swap(d.second[c - 4], d.second[c]);
d.first.insert(d.second[c]);
b.push(d);
}
}
b.pop();
}
if (b.empty()) cout << "No";
else cout << "Yes";
}