結果

問題 No.3224 2×2行列入門
ユーザー Cafe1942
提出日時 2025-08-08 21:23:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 118,108 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-08 21:23:26
合計ジャッジ時間 1,791 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

vector<vector<ll>> mul(vector<vector<ll>>& A, vector<vector<ll>>& B, int size) {
	vector<vector<ll>>res;
	for (int i = 0; i < size; i++) {
		vector<ll>row;
		for (int j = 0; j < size; j++) {
			ll tmp = 0;
			for (int k = 0; k < size; k++) {
				tmp += A[i][k] * B[k][j];
			}
			row.push_back(tmp);
		}
		res.push_back(row);
	}
	return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	vector<ll>I(2);
	vector<vector<ll>>A(2, I), B(2, I);
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			cin >> A[i][j];
		}
	}

	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			cin >> B[i][j];
		}
	}
	auto C = mul(A, B, 2);
	auto D = mul(C, C, 2);
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			cout << D[i][j] << " ";
		}
		cout << "\n";
	}
    return 0;
}

0