Skip to content

Commit c0075cf

Browse files
committed
Support dynamic_modint in matrix ops
1 parent f05e218 commit c0075cf

19 files changed

+39
-7
lines changed

cp-algo/algebra/common.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ namespace cp_algo::algebra {
4343
}
4444
return F[n];
4545
}
46-
4746
template<typename T>
4847
T rfact(int n) {
4948
static std::vector<T> F(maxn);
@@ -57,7 +56,6 @@ namespace cp_algo::algebra {
5756
}
5857
return F[n];
5958
}
60-
6159
template<typename T>
6260
T small_inv(int n) {
6361
static std::vector<T> F(maxn);

cp-algo/linalg/vector.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ namespace cp_algo::linalg {
120120
using Base::Base;
121121
};
122122

123-
template<int mod>
124-
struct vec<algebra::modint<mod>>:
125-
vec_base<vec<algebra::modint<mod>>, algebra::modint<mod>> {
126-
using base = algebra::modint<mod>;
123+
template<typename base>
124+
requires(std::is_base_of_v<algebra::modint_base<base>, base>)
125+
struct vec<base>: vec_base<vec<base>, base> {
127126
using Base = vec_base<vec<base>, base>;
128127
using Base::Base;
129128

File renamed without changes.
File renamed without changes.
File renamed without changes.

verify/algebra/matrix/prod.test.cpp renamed to verify/linalg/prod.test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
using namespace std;
99
using namespace cp_algo::linalg;
1010
using namespace cp_algo::algebra;
11+
using base = dynamic_modint;
1112

1213
const int mod = 998244353;
1314

1415
void solve() {
16+
base::switch_mod(mod);
1517
int n, m, k;
1618
cin >> n >> m >> k;
17-
matrix<modint<mod>> a(n, m), b(m, k);
19+
matrix<base> a(n, m), b(m, k);
1820
a.read();
1921
b.read();
2022
(a * b).print();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @brief Matrix Product (dynamic modint)
2+
#define PROBLEM "https://judge.yosupo.jp/problem/matrix_product"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#pragma GCC target("avx2,tune=native")
5+
#include "cp-algo/linalg/matrix.hpp"
6+
#include <bits/stdc++.h>
7+
8+
using namespace std;
9+
using namespace cp_algo::linalg;
10+
using namespace cp_algo::algebra;
11+
using base = dynamic_modint;
12+
13+
const int mod = 998244353;
14+
15+
void solve() {
16+
base::switch_mod(mod);
17+
int n, m, k;
18+
cin >> n >> m >> k;
19+
matrix<base> a(n, m), b(m, k);
20+
a.read();
21+
b.read();
22+
(a * b).print();
23+
}
24+
25+
signed main() {
26+
//freopen("input.txt", "r", stdin);
27+
ios::sync_with_stdio(0);
28+
cin.tie(0);
29+
int t = 1;
30+
while(t--) {
31+
solve();
32+
}
33+
}
File renamed without changes.

0 commit comments

Comments
 (0)