結果

問題 No.2441 行列累乗
ユーザー ripity
提出日時 2023-08-25 21:29:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 3,467 ms
コンパイル使用メモリ 254,528 KB
最終ジャッジ日時 2025-02-16 13:44:56
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/all>
using namespace atcoder;

vector<vector<int>> matrix_product(vector<vector<int>> A, vector<vector<int>> B) {
	int H = A.size(), W = B[0].size(), K = A[0].size();
	vector<vector<int>> ret(H, vector<int>(W));
	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			for( int k = 0; k < K; k++ ) {
				ret[i][j] += A[i][k]*B[k][j];
			}
		}
	}
	return ret;
}

int main() {
	int a, b, c, d, p, q, r, s;
	cin >> a >> b >> c >> d;
	vector<vector<int>> M = {{a, b}, {c, d}}, ans = {{1, 0}, {0, 1}};
	ans = matrix_product(ans, M);
	ans = matrix_product(ans, M);
	ans = matrix_product(ans, M);
	cout << ans[0][0] << " " << ans[0][1] << endl;
	cout << ans[1][0] << " " << ans[1][1] << endl;
}
0