結果
問題 | No.675 ドットちゃんたち |
ユーザー |
|
提出日時 | 2018-04-15 02:53:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 271 ms / 2,000 ms |
コード長 | 1,582 bytes |
コンパイル時間 | 2,510 ms |
コンパイル使用メモリ | 206,160 KB |
最終ジャッジ日時 | 2025-01-05 10:14:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> using vec = vector<T>; using mat = vec<vec<int>>; mat operator *(mat a, mat b) { mat c = mat(a.size(), vec<int>(b[0].size())); for (int i = 0; i < a.size(); ++i) { for (int k = 0; k < b.size(); ++k) { for (int j = 0; j < b[0].size(); ++j) { c[i][j] += a[i][k] * b[k][j]; } } } return c; } signed main() { ios::sync_with_stdio(false); int N, Px, Py; cin >> N >> Px >> Py; mat x = mat(3, vec<int>(1)); x[0][0] = Px; x[1][0] = Py; x[2][0] = 1; mat prod_t = mat(3, vec<int>(3)); for (int i = 0; i < 3; ++i) { prod_t[i][i] = 1; } vector<int> OP; for (int i = 0; i < N; ++i) { int op; cin >> op; if (op < 3) { int u; cin >> u; OP.emplace_back(u); } OP.emplace_back(op); } reverse(OP.begin(), OP.end()); vector<pair<int, int>> ans(N); for (int i = 0, ptr = 0; i < N; ++i) { int op = OP[ptr++]; mat t = mat(3, vec<int>(3)); if (op == 1) { int Dx = OP[ptr++]; for (int j = 0; j < 3; ++j) { t[j][j] = 1; } t[0][2] = Dx; } else if (op == 2) { int Dy = OP[ptr++]; for (int j = 0; j < 3; ++j) { t[j][j] = 1; } t[1][2] = Dy; } else { t[0][1] = 1; t[1][0] = -1; t[2][2] = 1; } prod_t = prod_t * t; mat res = prod_t * x; ans[N - 1 - i] = make_pair(res[0][0], res[1][0]); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i].first << ' ' << ans[i].second << endl; } return 0; }