結果

問題 No.471 直列回転機
ユーザー kyunakyuna
提出日時 2019-09-24 12:24:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 511 ms / 3,141 ms
コード長 3,062 bytes
コンパイル時間 3,426 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 24,396 KB
平均クエリ数 19589.39
最終ジャッジ日時 2023-09-02 04:01:02
合計ジャッジ時間 20,109 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,520 KB
testcase_01 AC 26 ms
23,508 KB
testcase_02 AC 26 ms
23,364 KB
testcase_03 AC 26 ms
24,024 KB
testcase_04 AC 26 ms
23,940 KB
testcase_05 AC 28 ms
23,580 KB
testcase_06 AC 26 ms
23,580 KB
testcase_07 AC 27 ms
23,580 KB
testcase_08 AC 75 ms
23,448 KB
testcase_09 AC 78 ms
23,628 KB
testcase_10 AC 47 ms
23,520 KB
testcase_11 AC 213 ms
23,736 KB
testcase_12 AC 411 ms
23,304 KB
testcase_13 AC 437 ms
23,580 KB
testcase_14 AC 469 ms
24,276 KB
testcase_15 AC 511 ms
23,940 KB
testcase_16 AC 30 ms
23,328 KB
testcase_17 AC 27 ms
23,328 KB
testcase_18 AC 26 ms
23,952 KB
testcase_19 AC 25 ms
24,036 KB
testcase_20 AC 498 ms
23,736 KB
testcase_21 AC 116 ms
23,364 KB
testcase_22 AC 443 ms
23,448 KB
testcase_23 AC 425 ms
23,364 KB
testcase_24 AC 254 ms
23,352 KB
testcase_25 AC 88 ms
23,940 KB
testcase_26 AC 492 ms
23,568 KB
testcase_27 AC 233 ms
23,616 KB
testcase_28 AC 285 ms
23,544 KB
testcase_29 AC 325 ms
24,216 KB
testcase_30 AC 136 ms
24,396 KB
testcase_31 AC 488 ms
23,340 KB
testcase_32 AC 398 ms
23,340 KB
testcase_33 AC 318 ms
23,280 KB
testcase_34 AC 465 ms
23,460 KB
testcase_35 AC 114 ms
23,628 KB
testcase_36 AC 195 ms
23,448 KB
testcase_37 AC 59 ms
23,532 KB
testcase_38 AC 99 ms
23,436 KB
testcase_39 AC 167 ms
23,328 KB
testcase_40 AC 338 ms
24,204 KB
testcase_41 AC 504 ms
23,328 KB
testcase_42 AC 320 ms
23,448 KB
testcase_43 AC 453 ms
24,216 KB
testcase_44 AC 60 ms
23,952 KB
testcase_45 AC 305 ms
23,328 KB
testcase_46 AC 342 ms
23,304 KB
testcase_47 AC 463 ms
23,364 KB
testcase_48 AC 398 ms
23,280 KB
testcase_49 AC 376 ms
23,628 KB
testcase_50 AC 442 ms
23,304 KB
testcase_51 AC 188 ms
23,940 KB
testcase_52 AC 28 ms
24,324 KB
testcase_53 AC 29 ms
23,640 KB
testcase_54 AC 28 ms
24,024 KB
testcase_55 AC 121 ms
23,940 KB
testcase_56 AC 110 ms
23,340 KB
testcase_57 AC 72 ms
23,364 KB
testcase_58 AC 51 ms
23,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto &vi: vec) os << vi << " "; return os;
}
template<class T> struct Matrix {
    vector<vector<T>> val;
    Matrix(int n = 1, int m = 1, T x = 0) { val.assign(n, vector<T>(m, x)); }
    size_t size() const { return val.size(); }
    vector<T>& operator[](int i) { return val[i]; }
    const vector<T>& operator[](int i) const { return val[i]; }
    friend ostream& operator<<(ostream& os, const Matrix<T> M) {
        for (int i = 0; i < M.size(); ++i) os << M[i] << " \n"[i != M.size() - 1];
        return os;
    }
};
template<class T> Matrix<T> operator^(Matrix<T> A, long long n) {
    Matrix<T> R(A.size(), A.size());
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; }
    return R;
}
template<class T> Matrix<T> operator*(const Matrix<T>& A, const Matrix<T>& B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j)
        for (int k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];
    return R;
}
template<class T> vector<T> operator*(const Matrix<T> &A, vector<T> &B) {
    vector<T> v(A.size());
    for (int i = 0; i < A.size(); ++i)
        for (int k = 0; k < B.size(); ++k) v[i] += A[i][k] * B[k];
    return v;
}
template<class T> T affine2(T a, T b, long long n, T x1 = 1) {
    Matrix<T> A(2, 2);
    A[0][0] = a; A[0][1] = b;                   // x[k + 1] = a * x[k] + b
    A[1][0] = 0; A[1][1] = 1;
    auto pow = A ^ (n - 1);
    return pow[0][0] * x1 + pow[0][1];
}
template<class T>
Matrix<T> affine2D(T p = T(1), T q = T(0), T r = T(0), T s = T(1), T b1 = T(0), T b2 = T(0)) {
    Matrix<T> A(3, 3);
    A[0][0] = p; A[0][1] = q; A[0][2] = b1;     // ⎛y1⎞   ⎛p q⎞ ⎛x1⎞   ⎛b1⎞
    A[1][0] = r; A[1][1] = s; A[1][2] = b2;     // ⎝y2⎠ = ⎝r s⎠ ⎝x2⎠ * ⎝b2⎠
    A[2][0] = 0; A[2][1] = 0; A[2][2] =  1;
    return A;
}
template<class T> Matrix<T> rot(T theta) {
    return affine2D(cos(theta), -sin(theta), sin(theta), cos(theta), 0, 0);
}
template<class T> Matrix<T> rot_cw90() { return affine2D(T(0), T(1), -T(1), T(0), T(0), T(0)); }
template<class T> Matrix<T> rot_ccw90() { return affine2D(T(0), -T(1), T(1), T(0), T(0), T(0)); }
template<class T> Matrix<T> trans(T b1, T b2) { return affine2D(T(1), T(0), T(0), T(1), b1, b2); }

int main() {
    int n; cin >> n;
    vector<vector<int>> p(n, vector<int>(3, 1));
    for (int i = 0; i < n; i++) cin >> p[i][0] >> p[i][1];
    cout << "? 0 0" << endl;
    int dx, dy; cin >> dx >> dy;
    cout << "? 1 0" << endl;
    int a, c; cin >> a >> c; a -= dx, c -= dy;
    cout << "? 0 1" << endl;
    int b, d; cin >> b >> d; b -= dx, d -= dy;
    Matrix<int> affine = affine2D(a, b, c, d, dx, dy);
    cout << "!" << endl;
    for (int i = 0; i < n; i++) {
        auto res = affine * p[i];
        cout << res[0] << " " << res[1] << endl;
    }
    return 0;
}
0