結果

問題 No.3006 ベイカーの問題
ユーザー haihamabossu
提出日時 2025-02-11 02:27:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,417 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 204,768 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-11 02:27:13
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template <typename T>
vector<vector<T>> mat_dot(const vector<vector<T>> &lhs,
                          const vector<vector<T>> &rhs) {
  int sz = lhs.size();
  vector res(sz, vector<T>(sz, 0));
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      for (int k = 0; k < sz; k++) {
        res[i][j] += lhs[i][k] * rhs[k][j];
      }
    }
  }
  return res;
}

template <typename T>
vector<vector<T>> mat_pow(const vector<vector<T>> &mat, long long n) {
  int sz = mat.size();
  vector res(sz, vector<T>(sz, 0));
  for (int i = 0; i < sz; i++) {
    res[i][i] = 1;
  }
  auto now = mat;
  while (n > 0) {
    if (n & 1) {
      res = mat_dot(now, res);
    }
    now = mat_dot(now, now);
    n >>= 1;
  }
  return res;
}

void solve() {
  ll x1, y1, n;
  cin >> x1 >> y1 >> n;
  vector<vector<mint>> mat = {
      {x1, -5 * y1, 0, 0},
      {y1, x1, 0, 0},
      {1, 0, 1, 0},
      {0, 1, 0, 1},
  };
  auto a = mat_pow(mat, n);
  mint x = a[2][0] * x1 + a[2][1] * y1;
  mint y = a[3][0] * x1 + a[3][1] * y1;
  cout << x.val() << ' ' << y.val() << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0