結果

問題 No.675 ドットちゃんたち
ユーザー PachicobuePachicobue
提出日時 2018-09-14 18:11:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 207,136 KB
実行使用メモリ 5,996 KB
最終ジャッジ日時 2023-09-19 09:23:39
合計ジャッジ時間 4,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 148 ms
5,952 KB
testcase_06 AC 156 ms
5,996 KB
testcase_07 AC 143 ms
5,856 KB
testcase_08 AC 147 ms
5,916 KB
testcase_09 AC 158 ms
5,936 KB
testcase_10 AC 159 ms
5,864 KB
testcase_11 AC 158 ms
5,984 KB
権限があれば一括ダウンロードができます

ソースコード

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