結果
| 問題 |
No.585 工夫のないパズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-12 22:10:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,829 bytes |
| コンパイル時間 | 1,049 ms |
| コンパイル使用メモリ | 110,632 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-24 23:18:47 |
| 合計ジャッジ時間 | 3,413 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 12 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
unsigned xor128()
{
static unsigned x=123456789,y=362436069,z=521288629,w=88675123;
unsigned t;
t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
class Data
{
public:
char type;
int pos, len;
Data(char type, int pos, int len){
this->type = type;
this->pos = pos;
this->len = (len % 4 + 4) % 4;
}
};
void rotatePuzzle(vector<string>& puzzle, Data& d)
{
if(d.type == 'r'){
string s(4, ' ');
for(int i=0; i<4; ++i)
s[i] = puzzle[i][d.pos];
for(int i=0; i<4; ++i)
puzzle[(d.len+i)%4][d.pos] = s[i];
}
else{
string& s = puzzle[d.pos];
rotate(s.begin(), s.begin() + 4 - d.len, s.end());
}
}
void moveCell(vector<string>& puzzle, char c, int y, int x, vector<Data>& ans)
{
int y2, x2;
for(int i=0; ; ++i){
y2 = i / 4;
x2 = i % 4;
if(puzzle[y2][x2] == c)
break;
}
if(y == y2 && x == x2)
return;
if(x2 == x){
ans.push_back(Data('c', y2, 1));
rotatePuzzle(puzzle, ans.back());
x2 = (x2 + 1) % 4;
}
ans.push_back(Data('r', x, 3 - y));
rotatePuzzle(puzzle, ans.back());
if(y2 != 3){
ans.push_back(Data('r', x2, 3 - y2));
rotatePuzzle(puzzle, ans.back());
}
ans.push_back(Data('c', 3, x - x2));
rotatePuzzle(puzzle, ans.back());
ans.push_back(Data('r', x, y - 3));
rotatePuzzle(puzzle, ans.back());
if(y2 != 3){
ans.push_back(Data('r', x2, y2 - 3));
rotatePuzzle(puzzle, ans.back());
}
}
bool solve(vector<string> puzzle, vector<Data>& ans)
{
ans.clear();
for(int i=0; i<20; ++i){
int type = xor128() % 2 == 0 ? 'r' : 'c';
int pos = xor128() % 4;
int len = xor128() % 4;
ans.push_back(Data(type, pos, len));
rotatePuzzle(puzzle, ans.back());
}
for(int i=0; i<12; ++i){
int y = i / 4;
int x = i % 4;
char c = 'A' + i;
moveCell(puzzle, c, y, x, ans);
}
return puzzle[3] == "MNOP";
}
int main()
{
vector<string> puzzle(4);
for(int i=0; i<4; ++i)
cin >> puzzle[i];
vector<Data> ans;
while(!solve(puzzle, ans));
cout << ans.size() << endl;
for(const Data& d : ans)
cout << d.type << ' ' << d.pos << ' ' << d.len << endl;
return 0;
}