結果
| 問題 |
No.675 ドットちゃんたち
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2021-02-22 05:43:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 158 ms / 2,000 ms |
| コード長 | 3,517 bytes |
| コンパイル時間 | 2,193 ms |
| コンパイル使用メモリ | 209,140 KB |
| 最終ジャッジ日時 | 2025-01-19 03:19:51 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <typename T>
struct Matrix {
Matrix(int m, int n, T val = 0) : dat(m, std::vector<T>(n, val)) {}
int height() const { return dat.size(); }
int width() const { return dat.front().size(); }
Matrix pow(long long exponent) const {
int n = height();
Matrix<T> tmp = *this, res(n, n, 0);
for (int i = 0; i < n; ++i) res[i][i] = 1;
while (exponent > 0) {
if (exponent & 1) res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
inline const std::vector<T> &operator[](const int idx) const { return dat[idx]; }
inline std::vector<T> &operator[](const int idx) { return dat[idx]; }
Matrix &operator=(const Matrix &x) {
int m = x.height(), n = x.width();
dat.resize(m, std::vector<T>(n));
for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] = x[i][j];
return *this;
}
Matrix &operator+=(const Matrix &x) {
int m = height(), n = width();
for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] += x[i][j];
return *this;
}
Matrix &operator-=(const Matrix &x) {
int m = height(), n = width();
for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) dat[i][j] -= x[i][j];
return *this;
}
Matrix &operator*=(const Matrix &x) {
int m = height(), n = x.width(), l = width();
std::vector<std::vector<T>> res(m, std::vector<T>(n, 0));
for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) {
for (int k = 0; k < l; ++k) res[i][j] += dat[i][k] * x[k][j];
}
std::swap(dat, res);
return *this;
}
Matrix operator+(const Matrix &x) const { return Matrix(*this) += x; }
Matrix operator-(const Matrix &x) const { return Matrix(*this) -= x; }
Matrix operator*(const Matrix &x) const { return Matrix(*this) *= x; }
private:
std::vector<std::vector<T>> dat;
};
int main() {
int n; cin >> n;
Matrix<int> p(3, 1, 1); cin >> p[0][0] >> p[1][0];
vector<int> type(n), d(n);
REP(i, n) {
cin >> type[i];
if (type[i] == 1 || type[i] == 2) cin >> d[i];
}
vector<Matrix<int>> a;
Matrix<int> m(3, 3);
REP(i, 3) m[i][i] = 1;
for (int i = n - 1; i >= 0; --i) {
Matrix<int> command(3, 3);
command[2][2] = 1;
if (type[i] == 1) {
command[0][0] = command[1][1] = 1;
command[0][2] = d[i];
} else if (type[i] == 2) {
command[0][0] = command[1][1] = 1;
command[1][2] = d[i];
} else if (type[i] == 3) {
command[0][1] = 1;
command[1][0] = -1;
}
m *= command;
a.emplace_back(m * p);
}
reverse(ALL(a));
REP(i, n) cout << a[i][0][0] << ' ' << a[i][1][0] << '\n';
return 0;
}
emthrm