#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 250005
#define MOD ll(998244353)
using namespace std;
typedef long long ll;
typedef long double ld;
int mt[N], idr[505][505];
pair <int, int> conv[505 * 505];
vector <pair <int, int> > g[N], gr[N];
bool mk[N], mkr[N], was[N];
bool kuna(int v)
{
if (mk[v]) return 0;
mk[v] = 1;
for (auto it : g[v])
{
if (mt[it.F] == -1 || kuna(mt[it.F]))
{
mt[it.F] = v;
was[it.F] = 1;
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 s[n];
for (int i = 0; i < n; i++) cin >> s[i];
int id = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {conv[id] = {i, j}; idr[i][j] = id++;}
int koler = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (s[i][j] == '0')
{
int x = i;
while (s[x][j] == '0') x--;
int y = j;
while (s[i][y] == '0') y--;
g[idr[x][j]].pb({idr[i][y], koler});
gr[idr[i][y]].pb({idr[x][j], koler++});
}
memset(mt, -1, sizeof(mt));
for (int i = 0; i < N; i++)
{
if (sz(g[i]) == 0 || was[i]) continue;
memset(mk, 0, sizeof(mk));
was[i] = kuna(i);
}
vector <pair <pair <int, int>, int> > ans; ans.clear();
for (int i = 0; i < N; i++)
if (mt[i] != -1)
{
int kol = 0;
for (auto it : g[mt[i]])
if (!mkr[it.S]) kol++;
for (auto it : gr[i])
if (!mkr[it.S]) kol--;
if (kol > 0)
{
for (auto it : g[mt[i]]) mkr[it.S] = 1;
ans.pb({{conv[mt[i]]}, 1});
}
else
{
for (auto it : g[i]) mkr[it.S] = 1;
ans.pb({{conv[i]}, 0});
}
}
cout << sz(ans) << endl;
for (auto it : ans) cout << it.F.F + 1 << " " << it.F.S + 1 << " " << (it.S == 0 ? "DESNO" : "DOLJE") << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
13312 KB |
Correct. |
2 |
Incorrect |
13 ms |
13312 KB |
First line is not correct. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
14208 KB |
Correct. |
2 |
Incorrect |
14 ms |
13696 KB |
First line is not correct. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
13312 KB |
Correct. |
2 |
Incorrect |
13 ms |
13312 KB |
First line is not correct. |
3 |
Halted |
0 ms |
0 KB |
- |