結果

問題 No.675 ドットちゃんたち
ユーザー merom686merom686
提出日時 2018-04-14 17:46:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 76,092 KB
実行使用メモリ 4,432 KB
最終ジャッジ日時 2023-09-09 05:20:51
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 19 ms
4,432 KB
testcase_06 AC 29 ms
4,424 KB
testcase_07 AC 25 ms
4,380 KB
testcase_08 AC 24 ms
4,384 KB
testcase_09 AC 27 ms
4,380 KB
testcase_10 AC 28 ms
4,380 KB
testcase_11 AC 27 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int x, y, r;
};

void rot(int& x, int& y, int r) {
    r &= 3;
    if (r == 0) {
        return;
    } else if (r == 1) {
        int t = x; x = -y; y = t;
    } else if (r == 2) {
        x = -x; y = -y;
    } else if (r == 3) {
        int t = x; x = y; y = -t;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, px, py;
    cin >> n >> px >> py;

    vector<P> p(n + 1);
    p[0] = { 0, 0, 0 };
    int x = 0, y = 0, r = 0;

    for (int i = 0; i < n; i++) {
        int c;
        cin >> c;

        if (c != 3) {
            int d[2] = {};
            cin >> d[c == 2];
            rot(d[0], d[1], r);
            x += d[0];
            y += d[1];
        } else {
            r++;
        }
        p[i + 1] = { x, y, r };
    }

    for (int i = 0; i < n; i++) {
        int x = px, y = py;
        rot(x, y, p[i].r);

        x += p[n].x - p[i].x;
        y += p[n].y - p[i].y;

        rot(x, y, -p[n].r);

        cout << x << ' ' << y << '\n';
    }

    return 0;
}
0