結果
| 問題 |
No.2825 Sum of Scores of Sets of Specified Sections
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2024-07-26 23:15:54 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 3,000 ms |
| コード長 | 1,361 bytes |
| コンパイル時間 | 3,171 ms |
| コンパイル使用メモリ | 255,360 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-26 23:15:59 |
| 合計ジャッジ時間 | 5,120 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
template <class T> T determinant(vector<vector<T>> a) {
T det = 1;
for (int j = 0, r = 0, n = a.size(); j < n; ++j, ++r) {
for (int i = r + 1; i < n; ++i)
if (!(a[i][j] == 0)) {
swap(a[r], a[i]), det = -det;
break;
}
if (a[r][j] == 0) return 0;
det *= a[r][j];
T inv = 1 / a[r][j];
for (auto&& e : a[r]) e *= inv;
for (int i = 0; i < n; ++i)
if (i != r and !(a[i][j] == 0))
for (int k = n; k-- > j;) a[i][k] -= a[r][k] * a[i][j];
}
return det;
}
using Mint = atcoder::modint998244353;
istream& operator>>(istream& is, Mint& x) {
int v;
is >> v;
x = Mint::raw(v);
return is;
}
void Solve() {
int n, m;
cin >> n >> m;
vector a(n, vector<Mint>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
vector b(n, vector<Mint>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> b[i][j];
}
}
vector c(n, vector<Mint>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
c[i][j] = inner_product(a[i].begin(), a[i].end(), b[j].begin(), Mint(i == j));
}
}
cout << (determinant(c) - 1).val() << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}
risujiroh