結果

問題 No.3224 2×2行列入門
コンテスト
ユーザー KKT89
提出日時 2026-02-14 23:13:38
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 724 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,768 ms
コンパイル使用メモリ 210,292 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-14 23:13:41
合計ジャッジ時間 3,227 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using longll = long long;

struct Mat {
    longll a, b, c, d; // [ [a b], [c d] ]
};

Mat mul(const Mat& x, const Mat& y) {
    // x * y
    return Mat{
        x.a * y.a + x.b * y.c,
        x.a * y.b + x.b * y.d,
        x.c * y.a + x.d * y.c,
        x.c * y.b + x.d * y.d
    };
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    longll A, B, C, D, Ap, Bp, Cp, Dp;
    cin >> A >> B >> C >> D >> Ap >> Bp >> Cp >> Dp;

    Mat M{A, B, C, D};
    Mat Mp{Ap, Bp, Cp, Dp};

    Mat P = mul(M, Mp);   // MM'
    Mat R = mul(P, P);    // (MM')(MM') = MM'MM'

    cout << R.a << " " << R.b << "\n";
    cout << R.c << " " << R.d << "\n";
    return 0;
}
0