結果

問題 No.3006 ベイカーの問題
ユーザー 👑 獅子座じゃない人
提出日時 2025-01-17 22:23:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,897 bytes
コンパイル時間 4,242 ms
コンパイル使用メモリ 174,412 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-17 22:24:10
合計ジャッジ時間 4,807 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "yukicoder/play/455/e.cpp"
#include <iostream>
using namespace std;
using ll=long long;
using ull=unsigned long long;

#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353;

#define rep(i, e) for(int i=0; i<(int)(e); ++i)
#define dir(dx, dy) for(auto [dx, dy]: vector{pair{1, 0}, {0, 1}, {-1, 0}, {0, -1}})

#define all(v) (v).begin(), (v).end()
#define all_r(v) (v).rbegin(), (v).rend()

#define in(i) cin >> i
#define in_d(type, i) type i; cin >> i
#define in_z(i) cin >> i; --i
#define in_d_z(type, i) type i; cin >> i; --i
#define out(i) cout << (i) << endl
#define err(i) cerr << (i) << endl
#define out_e() cout << endl
#define err_e() cerr << endl
#define out_s(i) cout << (i) << " "
#define err_s(i) cerr << (i) << " "

#define out_f(i) cout << fixed << setprecision(15) << (i) << endl
#define err_f(i) cerr << fixed << setprecision(15) << (i) << endl
#define out_fs(i) cout << fixed << setprecision(15) << (i) << " "
#define err_fs(i) cerr << fixed << setprecision(15) << (i) << " "

constexpr int max32=1'000'000'000;
constexpr ll max64=1'000'000'000'000'000'000;

template <typename T>
bool chmin(T & l, const T & r) {
    if(r<l){
        l=r;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T & l, const T & r) {
    if(r>l){
        l=r;
        return true;
    }
    return false;
}

#include <array>
#line 1 "/opt/ei1333_s_library/math/matrix/square-matrix.hpp"
/**
 * @brief Square-Matrix(正方行列)
 */
template <class T, size_t N>
struct SquareMatrix {
  array<array<T, N>, N> A;

  SquareMatrix() : A{{}} {}

  size_t size() const { return N; }

  inline const array<T, N> &operator[](int k) const { return (A.at(k)); }

  inline array<T, N> &operator[](int k) { return (A.at(k)); }

  static SquareMatrix add_identity() { return SquareMatrix(); }

  static SquareMatrix mul_identity() {
    SquareMatrix mat;
    for (size_t i = 0; i < N; i++) mat[i][i] = 1;
    return mat;
  }

  SquareMatrix &operator+=(const SquareMatrix &B) {
    for (size_t i = 0; i < N; i++) {
      for (size_t j = 0; j < N; j++) {
        (*this)[i][j] += B[i][j];
      }
    }
    return *this;
  }

  SquareMatrix &operator-=(const SquareMatrix &B) {
    for (size_t i = 0; i < N; i++) {
      for (size_t j = 0; j < N; j++) {
        (*this)[i][j] -= B[i][j];
      }
    }
    return *this;
  }

  SquareMatrix &operator*=(const SquareMatrix &B) {
    array<array<T, N>, N> C;
    for (size_t i = 0; i < N; i++) {
      for (size_t j = 0; j < N; j++) {
        for (size_t k = 0; k < N; k++) {
          C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);
        }
      }
    }
    A.swap(C);
    return (*this);
  }

  SquareMatrix &operator^=(unsigned long long k) {
    SquareMatrix B = SquareMatrix::mul_identity();
    while (k > 0) {
      if (k & 1) B *= *this;
      *this *= *this;
      k >>= 1LL;
    }
    A.swap(B.A);
    return *this;
  }

  SquareMatrix operator+(const SquareMatrix &B) const {
    return SquareMatrix(*this) += B;
  }

  SquareMatrix operator-(const SquareMatrix &B) const {
    return SquareMatrix(*this) -= B;
  }

  SquareMatrix operator*(const SquareMatrix &B) const {
    return SquareMatrix(*this) *= B;
  }

  SquareMatrix operator^(unsigned long long k) const { return SquareMatrix(*this) ^= k; }

  friend ostream &operator<<(ostream &os, SquareMatrix &p) {
    for (int i = 0; i < N; i++) {
      os << "[";
      for (int j = 0; j < N; j++) {
        os << p[i][j] << (j + 1 == N ? "]\n" : ",");
      }
    }
    return os;
  }
};
#line 54 "yukicoder/play/455/e.cpp"

int main(void) {
    in_d(ll, x1);
    in_d(ll, y1);
    in_d(ll, n);
    SquareMatrix<mint, 4> m;
    m.A=array<array<mint, 4>, 4>{array<mint, 4>{x1, -5*y1, 0, 0}, {y1, x1, 0, 0}, {1, 0, 1, 0}, {0, 1, 0, 1}};
    m^=n;
    out_s((m[2][0]*x1+m[2][1]*y1).val());
    out((m[3][0]*x1+m[3][1]*y1).val());
    return 0;
}
0