結果
| 問題 | No.2441 行列累乗 |
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2023-08-25 21:23:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 919 bytes |
| コンパイル時間 | 1,811 ms |
| コンパイル使用メモリ | 200,632 KB |
| 最終ジャッジ日時 | 2025-02-16 13:39:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <class T>
using matrix = vector<vector<T>>;
template <class T>
matrix<T> operator*(const matrix<T>& a, const matrix<T>& b) {
int n = a.size();
matrix<T> ret(n, vector<T>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
ret[i][j] += a[i][k] * b[k][j];
}
}
}
return ret;
}
template <class T>
matrix<T> operator^(matrix<T> a, long long b) {
int n = a.size();
matrix<T> ret(n, vector<T>(n));
for (int i = 0; i < n; i++) {
ret[i][i] = 1;
}
while (b) {
if (b & 1) {
ret = ret * a;
}
a = a * a;
b >>= 1;
}
return ret;
}
int main() {
matrix<int> m(2, vector<int>(2));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cin >> m[i][j];
}
}
m = m ^ 3;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << m[i][j] << ' ';
}
cout << endl;
}
}
Today03