結果
| 問題 |
No.2825 Sum of Scores of Sets of Specified Sections
|
| コンテスト | |
| ユーザー |
みどりむし🦠
|
| 提出日時 | 2024-04-13 11:28:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 230 ms / 3,000 ms |
| コード長 | 4,220 bytes |
| コンパイル時間 | 1,401 ms |
| コンパイル使用メモリ | 120,604 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-26 20:01:00 |
| 合計ジャッジ時間 | 3,843 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 |
ソースコード
#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;
}
matrix& transpose() {
matrix res(this->width(), this->height());
for(const size_type i : std::views::iota(0, this->height())) {
for(const size_type j : std::views::iota(0, this->width())) {
res[j][i] = (*this)[i][j];
}
}
this->resize(res.height(), res.width());
this->_data = std::move(res._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(n, m); std::cin >> A >> B;
std::cout << (matrix<mint>::identity(n) + A * B.transpose()).det() - 1 << "\n";
return 0;
}
みどりむし🦠