Skip to content

Commit dd69e90

Browse files
committed
Fix rank + test
1 parent 5d053b9 commit dd69e90

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

cp-algo/linalg/matrix.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ namespace cp_algo::linalg {
151151
}
152152

153153
size_t rank() const {
154-
if(n() < m()) {
154+
if(n() > m()) {
155155
return T().rank();
156156
}
157-
return size(matrix(*this).gauss()[0]);
157+
return size(matrix(*this).echelonize()[0]);
158158
}
159159

160160
base det() const {

verify/algebra/matrix/rank.test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @brief Rank of Matrix
2+
#define PROBLEM "https://judge.yosupo.jp/problem/matrix_rank"
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::algebra;
10+
using namespace cp_algo::linalg;
11+
12+
const int mod = 998244353;
13+
using base = modular<mod>;
14+
15+
void solve() {
16+
int n, m;
17+
cin >> n >> m;
18+
matrix<base> A(n, m);
19+
A.read();
20+
cout << A.rank() << "\n";
21+
}
22+
23+
signed main() {
24+
//freopen("input.txt", "r", stdin);
25+
ios::sync_with_stdio(0);
26+
cin.tie(0);
27+
int t = 1;
28+
//cin >> t;
29+
while(t--) {
30+
solve();
31+
}
32+
}

0 commit comments

Comments
 (0)