This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 300001
#define MOD ll(998244353)
using namespace std;
typedef long long ll;
typedef long double ld;
int mt[N], idr[505][505];
vector <int> g[N];
bool mk[N];
bool kuna(int v)
{
if (mk[v]) return 0;
mk[v] = 1;
for (auto it : g[v])
{
if (mt[it] == -1 || kuna(mt[it]))
{
mt[it] = v;
return 1;
}
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
string a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int id = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) idr[i][j] = id++;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] == '0')
{
int x = i;
while (a[x][j] == '0') x--;
int y = j;
while (a[i][y] == '0') y--;
g[idr[x][j]].pb(idr[i][y]);
}
memset(mt, -1, sizeof(mt));
for (int i = 0; i < N; i++)
{
memset(mk, 0, sizeof(mk));
kuna(i);
}
int ans = 0;
for (int i = 0; i < N; i++) if (mt[i] != -1) ans++;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |