forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
61 lines (53 loc) · 1.49 KB
/
A.cpp
File metadata and controls
61 lines (53 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
const int BASE1 = int(1e9) + 9, BASE2 = int(1e9) + 7;
int m, n;
long long a[211][211], c[211][211];
long long power(long long x, long long y, int BASE)
{
if (!y) return 1;
long long res = power(x, y / 2, BASE);
res = res * res % BASE;
if (y % 2)
res = res * x % BASE;
return res;
}
int solve (long long MOD) {
vector<int> where (m, -1);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j) {
a[i][j] = (c[i][j] % MOD + MOD) % MOD;
}
int col, row;
for (col=0, row=0; col<m && row<n; ++col) {
int sel = row;
for (int i=row; i<n; ++i)
if (a[i][col] > a[sel][col])
sel = i;
if (a[sel][col] == 0)
continue;
for (int i=col; i<=m; ++i)
swap (a[sel][i], a[row][i]);
where[col] = row;
for (int i=0; i<n; ++i)
if (i != row) {
long long c = a[i][col] * power(a[row][col], MOD - 2, MOD) % MOD;
for (int j=col; j<=m; ++j)
a[i][j] = (a[i][j] - a[row][j] * c % MOD + MOD) % MOD;
}
++row;
}
return row;
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> c[i][j];
int r1 = solve(BASE1);
int r2 = solve(BASE2);
assert(r1 == r2);
cout << min(r1, r2) << endl;
// cout << min(solve(BASE1), solve(BASE2)) << endl;
}