結果

問題 No.675 ドットちゃんたち
ユーザー Pachicobue
提出日時 2018-09-14 18:11:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 199,756 KB
最終ジャッジ日時 2025-01-06 13:22:37
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N, Px, Py;
    std::cin >> N >> Px >> Py;
    int rot = 0, dx = 0, dy = 0;
    auto move = [&](const int Dx, const int Dy) {
        if (rot == 0) {
            dx += Dx, dy += Dy;
        } else if (rot == 1) {
            dx += Dy, dy -= Dx;
        } else if (rot == 2) {
            dx -= Dx, dy -= Dy;
        } else {
            dx -= Dy, dy += Dx;
        }
    };
    using P = std::pair<int, int>;
    using PP = std::pair<bool, P>;
    std::vector<P> ans;
    auto answer = [&]() {
        int X, Y;
        if (rot == 0) {
            X = Px, Y = Py;
        } else if (rot == 1) {
            X = Py, Y = -Px;
        } else if (rot == 2) {
            X = -Px, Y = -Py;
        } else {
            X = -Py, Y = Px;
        }
        ans.push_back({X + dx, Y + dy});
    };
    std::vector<PP> com;
    for (int i = 0; i < N; i++) {
        int Com, Dx = 0, Dy = 0;
        std::cin >> Com;
        if (Com == 1) {
            std::cin >> Dx;
        } else if (Com == 2) {
            std::cin >> Dy;
        }
        com.push_back({Com == 3, {Dx, Dy}});
    }
    std::reverse(com.begin(), com.end());
    for (const auto& c : com) {
        if (c.first) {
            (rot += 1) %= 4;
        } else {
            move(c.second.first, c.second.second);
        }
        answer();
    }
    std::reverse(ans.begin(), ans.end());
    for (const auto& p : ans) { std::cout << p.first << " " << p.second << std::endl; }
    return 0;
}
0