結果

問題 No.585 工夫のないパズル
ユーザー mamekinmamekin
提出日時 2017-11-12 22:11:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,829 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 109,728 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 11:02:05
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0