結果

問題 No.675 ドットちゃんたち
ユーザー 👑 emthrmemthrm
提出日時 2021-02-22 05:43:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 3,517 bytes
コンパイル時間 3,053 ms
コンパイル使用メモリ 216,656 KB
実行使用メモリ 29,692 KB
最終ジャッジ日時 2023-10-20 05:59:32
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 145 ms
29,692 KB
testcase_06 AC 158 ms
29,692 KB
testcase_07 AC 149 ms
29,612 KB
testcase_08 AC 152 ms
29,692 KB
testcase_09 AC 160 ms
29,692 KB
testcase_10 AC 158 ms
29,692 KB
testcase_11 AC 157 ms
29,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0