結果
問題 |
No.3224 2×2行列入門
|
ユーザー |
|
提出日時 | 2025-08-08 21:34:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 3,681 ms |
コンパイル使用メモリ | 273,456 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-08 21:34:20 |
合計ジャッジ時間 | 4,459 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> static inline constexpr void mul(std::array<std::array<int_fast64_t, 2>, 2>& result, const std::array<std::array<int_fast64_t, 2>, 2>& a, const std::array<std::array<int_fast64_t, 2>, 2>& b) noexcept { for (uint_fast32_t i = 0; i != 2; ++i) for (uint_fast32_t j = 0; j != 2; ++j) result[i][j] = a[i][0] * b[0][j] + a[i][1] * b[1][j]; } static inline constexpr std::array<std::array<int_fast64_t, 2>, 2> solve(const std::array<std::array<std::array<int_fast64_t, 2>, 2>, 2>& M) noexcept { std::array<std::array<std::array<int_fast64_t, 2>, 2>, 2> dp = { std::array<std::array<int_fast64_t, 2>, 2>{ std::array<int_fast64_t, 2>{ 1, 0 }, std::array<int_fast64_t, 2>{ 0, 1 } }, std::array<std::array<int_fast64_t, 2>, 2>{ std::array<int_fast64_t, 2>{ 1, 0 }, std::array<int_fast64_t, 2>{ 0, 1 } } }; for (uint_fast32_t i = 0; i != 4; ++i) mul(dp[(i & 1) ^ 1], dp[i & 1], M[i & 1]); return dp[0]; } static inline void output(const std::array<std::array<int_fast64_t, 2>, 2>& ans) noexcept { std::cout << ans[0][0] << ' ' << ans[0][1] << '\n' << ans[1][0] << ' ' << ans[1][1] << '\n'; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::array<std::array<std::array<int_fast64_t, 2>, 2>, 2> M; uint_fast32_t i, j, k; for (i = 0; i != 2; ++i) for (j = 0; j != 2; ++j) for (k = 0; k != 2; ++k) std::cin >> M[i][j][k]; output(solve(M)); return 0; }