結果
| 問題 | No.3230 Mutual Corresponding System |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 09:19:01 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 84 ms / 2,000 ms |
| + 612µs | |
| コード長 | 1,361 bytes |
| 記録 | |
| コンパイル時間 | 1,564 ms |
| コンパイル使用メモリ | 225,424 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-23 09:19:08 |
| 合計ジャッジ時間 | 4,694 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T>
vector<vector<T>> multima(vector<vector<T>> &A,vector<vector<T>> &B){
assert(A.at(0).size() == B.size() && B.size());
int H = A.size(),W = B.at(0).size();
vector<vector<T>> ret(H,vector<T>(W));
for(int i=0; i<H; i++) for(int k=0; k<W; k++){
long long now = -1;
for(int l=0; l<A.at(i).size(); l++) now = max(now,A.at(i).at(l)+B.at(l).at(k));
ret.at(i).at(k) = now;
}
return ret; //計算できる行列のみ.
}
template<typename T>
vector<vector<T>> Powmat(vector<vector<T>> A,vector<vector<T>> B,long long N){ //return A^N*B ABは行列;
//n*n行列A n*1行列Bと想定 O(n^3*logN).
assert(A.size() && A.size() == A.at(0).size() && N >= 0);
while(N){
if(N&1) B = multima(A,B);
A = multima(A,A); N >>= 1;
}
return B;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long N,M; cin >> N >> M;
vector<int> T(N);
for(auto &t : T) cin >> t;
vector<vector<long long>> A(N,vector<long long>(N)),B(N);
for(auto &h : A) for(auto &w : h) cin >> w;
for(int i=0; i<N; i++) for(int k=i+1; k<N; k++) swap(A.at(i).at(k),A.at(k).at(i));
for(int i=0; i<N; i++) B.at(i) = {T.at(i)};
B = Powmat(A,B,M);
for(auto &b : B) cout << b.at(0) << " "; cout << endl;
}