結果
問題 | No.675 ドットちゃんたち |
ユーザー | kyuna |
提出日時 | 2019-09-24 07:28:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 255 ms / 2,000 ms |
コード長 | 4,172 bytes |
コンパイル時間 | 995 ms |
コンパイル使用メモリ | 82,768 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-09-19 04:57:54 |
合計ジャッジ時間 | 4,202 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 223 ms
42,368 KB |
testcase_06 | AC | 255 ms
42,368 KB |
testcase_07 | AC | 216 ms
38,400 KB |
testcase_08 | AC | 240 ms
42,240 KB |
testcase_09 | AC | 246 ms
42,368 KB |
testcase_10 | AC | 253 ms
42,240 KB |
testcase_11 | AC | 243 ms
42,240 KB |
ソースコード
#include <algorithm> #include <iostream> #include <vector> using namespace std; //----------------------- int MOD; struct mint { int n; mint(int n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } }; mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; } mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } ostream &operator<<(ostream &os, mint a) { return os << a.n; } istream &operator>>(istream &is, mint& a) { return is >> a.n; } mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0; while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); } return mint(u); } mint operator^(mint a, long long n) { mint r = 1; while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; } bool operator<(const mint &a, const mint &b) { return a.n < b.n; } //----------------------- 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<long long> p(3, 1); cin >> p[0] >> p[1]; vector<Matrix<long long>> a(n); for (int i = n - 1; i >= 0; i--) { int com; cin >> com; if (com == 1) { long long dx; cin >> dx; a[i] = trans<long long>(dx, 0); } if (com == 2) { long long dy; cin >> dy; a[i] = trans<long long>(0, dy); } if (com == 3) a[i] = rot_cw90<long long>(); } vector<Matrix<long long>> acc(n + 1); acc[0] = Matrix<long long>(3, 3) ^ 0; for (int i = 0; i < n; i++) acc[i + 1] = acc[i] * a[i]; for (int i = n; i > 0; i--) { auto res = acc[i] * p; cout << res[0] << " " << res[1] << endl; } return 0; }