結果
| 問題 |
No.2825 Sum of Scores of Sets of Specified Sections
|
| コンテスト | |
| ユーザー |
みどりむし🦠
|
| 提出日時 | 2024-01-22 16:54:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,804 bytes |
| コンパイル時間 | 1,464 ms |
| コンパイル使用メモリ | 119,300 KB |
| 実行使用メモリ | 90,384 KB |
| 最終ジャッジ日時 | 2024-07-26 20:00:58 |
| 合計ジャッジ時間 | 6,136 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | TLE * 1 -- * 31 |
ソースコード
#include <cassert>
#include <iostream>
#include <vector>
#include <ranges>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
std::istream &operator>>(std::istream &is, mint &v) {
int r; is >> r, v = r;
return is;
}
std::ostream &operator<<(std::ostream &os, const mint &v) {
return os << v.val();
}
template<class ValueType>
struct matrix {
using size_type = std::ptrdiff_t;
using value_type = ValueType;
private:
size_type _height, _width;
std::vector<std::vector<value_type>> _data;
size_type height() const { return this->_height; }
size_type width() const { return this->_width; }
public:
matrix(const size_type n, const size_type m)
: _height(n), _width(m), _data(n, std::vector<value_type>(m))
{}
void resize(const size_type n, const size_type m) {
this->_height = n, this->_width = m;
this->_data.resize(n);
for(auto& row : this->_data) row.resize(m);
}
static matrix identity(const size_type n) {
matrix res(n, n);
for(const size_type i : std::views::iota(0, n)) res[i][i] = 1;
return res;
}
inline const std::vector<value_type> &operator[](const size_type p) const {
return this->_data[p];
}
inline std::vector<value_type> &operator[](const size_type p) { return this->_data[p]; }
matrix &operator+=(const matrix &rhs) {
const size_type n = this->height(), m = this->width();
assert(n == rhs.height() && m == rhs.width());
for(size_type i : std::views::iota(0, n)) {
for(size_type j : std::views::iota(0, m)) {
(*this)[i][j] += rhs[i][j];
}
}
return *this;
}
matrix &operator*=(const matrix &rhs) {
const size_type n = this->height(), m = rhs._width, l = this->width();
assert(l == rhs._height);
matrix product(n, m);
for(size_type i : std::views::iota(0, n)) {
for(size_type j : std::views::iota(0, m)) {
for(size_type k : std::views::iota(0, l)) {
product[i][j] += (*this)[i][k] * rhs[k][j];
}
}
}
this->resize(n, m);
this->_data = std::move(product._data);
return *this;
}
value_type det() const {
auto X = this->_data;
value_type res = 1;
for(const size_type i : std::views::iota(0, this->width())) {
size_type pivot = {-1};
for(const size_type j : std::views::iota(i, this->width())) {
if(X[j][i] != 0) pivot = j;
}
if(pivot == -1) return 0;
if(i != pivot) {
res *= -1;
std::swap(X[i], X[pivot]);
}
res *= X[i][i];
const value_type inv = 1 / X[i][i];
for(const size_type j : std::views::iota(0, this->width())) {
X[i][j] *= inv;
}
for(const size_type j : std::views::iota(i + 1, this->width())) {
const value_type v = X[j][i];
for(const size_type k : std::views::iota(0, this->width())) {
X[j][k] -= X[i][k] * v;
}
}
}
return res;
}
friend matrix operator+(matrix a, const matrix &b) { return a += b; }
friend matrix operator*(matrix a, const matrix &b) { return a *= b; }
friend std::istream &operator>>(std::istream &is, matrix &p) {
for(auto &row : p._data) {
for(auto &v : row) is >> v;
}
return is;
}
};
int main() {
int n, m; std::cin >> n >> m;
matrix<mint> A(n, m), B(m, n); std::cin >> A >> B;
std::cout << (matrix<mint>::identity(m) + B * A).det() << "\n";
return 0;
}
みどりむし🦠