結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
marimom7
|
| 提出日時 | 2016-01-26 19:39:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,280 bytes |
| コンパイル時間 | 656 ms |
| コンパイル使用メモリ | 70,164 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-21 17:37:54 |
| 合計ジャッジ時間 | 1,450 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 17 |
ソースコード
#include<stdio.h>
#include<iostream>
#include<queue>
#include<memory.h>
using namespace std;
const int fieldSize = 16;
enum FieldVect {
UP,
RIGHT,
DOWN,
LEFT
};
struct block {
int num = 0;
bool move = false;
};
void CommandAdd(FieldVect vec,vector<FieldVect> *buf,queue<vector<FieldVect>> *commandList) {
buf->push_back(vec);
commandList->push(*buf);
buf->pop_back();
}
int main() {
int field_input[fieldSize];
block field_basic[fieldSize];
block field[fieldSize];
queue<vector<FieldVect>> commandList;
vector<FieldVect> buf;
int index = -1;
int oldindex = -1;
FieldVect gv;
bool moved = false;
bool complate = false;
block box;
for (int i = 0; i < fieldSize; i++)field[i].num = field_basic[i].num = (i + 1)% fieldSize;
for (int i = 0; i < fieldSize; i++)cin >> field_input[i];
CommandAdd(UP, &buf, &commandList);
CommandAdd(LEFT, &buf, &commandList);
while (!commandList.empty())
{
buf = commandList.front();
commandList.pop();
complate = true;
for (int i = 0; i < fieldSize; i++)complate &= field[i].num == field_input[i];
if (!complate) {
memcpy(field, field_basic, sizeof(field));
index = fieldSize - 1;
moved = true;
for (int i = 0; i < buf.size(); i++) {
gv = buf[i];
oldindex = index;
switch (gv) {
case UP: {
index += -4;
if (index < 0)index = -1;
break;
}
case RIGHT: {
if (index % 4 + 1 >= 4) {
index = -1;
}
else {
index += 1;
}
break;
}
case DOWN: {
index += 4;
if (index >= fieldSize)index = -1;
break;
}
case LEFT: {
if (index % 4 - 1 < 0) {
index = -1;
}
else {
index += -1;
}
break;
}
default:index = -1; break;
}
if (index < 0 || index > fieldSize - 1)index = -1;
if (index != -1 && !field[index].move) {
field[index].move = true;
box = field[index];
field[index] = field[oldindex];
field[oldindex] = box;
}
else {
moved = false;
}
}
if (moved) {
CommandAdd(UP, &buf, &commandList);
CommandAdd(RIGHT, &buf, &commandList);
CommandAdd(LEFT, &buf, &commandList);
CommandAdd(DOWN, &buf, &commandList);
}
}
}
cout << (complate ? "YES" : "NO") << endl;
return 0;
}
marimom7