結果

問題 No.675 ドットちゃんたち
ユーザー koyoprokoyopro
提出日時 2020-01-06 01:02:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 3,686 bytes
コンパイル時間 1,270 ms
コンパイル使用メモリ 151,348 KB
実行使用メモリ 65,036 KB
最終ジャッジ日時 2023-08-14 22:30:26
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 91 ms
55,388 KB
testcase_06 AC 117 ms
65,036 KB
testcase_07 AC 99 ms
55,756 KB
testcase_08 AC 105 ms
61,808 KB
testcase_09 AC 109 ms
61,692 KB
testcase_10 AC 116 ms
64,832 KB
testcase_11 AC 107 ms
60,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

template<typename T> struct Pos {
    T x, y, z;
    Pos(){};
    Pos(T _x, T _y): x(_x), y(_y){};
    Pos(T _x, T _y, T _z): x(_x), y(_y), z(_z){};
    
    Pos operator * (T t) {
        return Pos(t * x, t * y, t * z);
    }
    Pos operator + (Pos q) {
        return Pos(x + q.x, y + q.y, z + q.z);
    }
    Pos operator - (Pos q) {
        return Pos(x - q.x, y - q.y, z - q.z);
    }
    int dot(Pos q) {
        return x*q.x + y*q.y + z*q.z;
    }
    Pos det(Pos q) {
        return Pos( y*q.z - z*q.y ,
                   z*q.x - x*q.z ,
                   x*q.y - y*q.x );
    }
    bool operator == (Pos q) {
        return (x == q.x) && (y == q.y) && (z == q.z);
    }
    Pos operator * ( const Pos& q ) {
        return det(q);
    }
    T operator % ( const Pos& q ) {
        return dot(q);
    }
    T operator[](int i) {
        switch (i) {
            case 0: return x;
            case 1: return y;
            default: return z;
        }
    }
    T norm() {
        return sqrt(x*x + y*y + z*z);
    }
};

template<typename T> struct Matrix {
    Pos<T> rows[3];
    
    Matrix(T a0, T a1, T a2,
           T b0, T b1, T b2,
           T c0, T c1, T c2)
    {
        rows[0] = *new Pos<T>(a0, a1, a2);
        rows[1] = *new Pos<T>(b0, b1, b2);
        rows[2] = *new Pos<T>(c0, c1, c2);
    }
    
    Pos<T> operator * (Pos<T> v) {
        return *new Pos<T>(rows[0].dot(v), rows[1].dot(v), rows[2].dot(v));
    }
    
    Pos<T> operator[](size_t i) {
        return rows[i];
    }
    
    Pos<T> col(size_t i) {
        return *new Pos<T>(rows[0][i], rows[1][i], rows[2][i]);
    }
    
    Matrix operator * ( Matrix& q ) {
        return *new Matrix(
                           rows[0]%q.col(0), rows[0]%q.col(1), rows[0]%q.col(2),
                           rows[1]%q.col(0), rows[1]%q.col(1), rows[1]%q.col(2),
                           rows[2]%q.col(0), rows[2]%q.col(1), rows[2]%q.col(2)
                           );
    }
};

/*================================*/

int N,X,Y;
struct Order{int c; int v;};

void solve() {
    cin>>N>>X>>Y;
    
    vector<Order> O(N);
    REP(i,N) {
        cin>>O[i].c;
        if (O[i].c<3) cin>>O[i].v;
    }
    
    auto rotate = Matrix<int>(0,1,0, -1,0,0, 0,0,1);
    auto convert = Matrix<int>(1,0,0, 0,1,0, 0,0,1);
    vector<Pos<int>> ans;
    RREP(i,N) {
        int c = O[i].c, v = O[i].v;
        if (c == 1) {
            auto move = Matrix<int>(1,0,v, 0,1,0, 0,0,1);
            convert = convert * move;
        }
        if (c==2) {
            auto move = Matrix<int>(1,0,0, 0,1,v, 0,0,1);
            convert = convert * move;
        }
        if (c==3){
            convert = convert * rotate;
        }
        auto pos = convert * Pos<int>(X, Y, 1);
        ans.push_back(pos);
    }
    reverse(ALL(ans));
    for (auto pos : ans) {
        out("%lld %lld\n", pos.x, pos.y);
    }
}

/*================================*/

signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    solve();
    
    return 0;
}
0