제출 #570657

#제출 시각아이디문제언어결과실행 시간메모리
570657NekoRollySkandi (COCI20_skandi)C++17
110 / 110
70 ms13296 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e2+4; const int inf = 1e9; int n,m,n1,n2,ans; vector<int> adj[N*N]; int L[N][N],U[N][N]; int _u[N*N],_v[N*N],dis[N*N]; pair<int,int> posU[N*N],posL[N*N]; char lab[N][N]; queue<int> d; bool vis[N*N]; bool bfs(){ for (int i=1; i<=n1; i++){ if (!_u[i]){ dis[i] = 0; d.push(i);} else dis[i] = inf; } dis[0] = inf; for (int u; d.size(); d.pop()){ u = d.front(); for (int v : adj[u]) if (dis[_v[v]] == inf){ dis[_v[v]] = dis[u] + 1; d.push(_v[v]); } } return dis[0] != inf; } bool dfs1(int u){ if (!u) return 1; for (int v : adj[u]) if (dis[_v[v]] == dis[u]+1 && dfs1(_v[v])){ _v[v] = u, _u[u] = v; return 1; } dis[u] = inf; return 0; } void dfs2(int u){ vis[u] = 1; for (int v : adj[u]) if (!vis[_v[v]]) dfs2(_v[v]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=0; i<n; i++) for (int j=0; j<m; j++){ cin >> lab[i][j]; if (lab[i][j] == '0'){ if (lab[i-1][j] == '0') U[i][j] = U[i-1][j]; else U[i][j] = ++n1, posU[n1] = {i, j}; if (lab[i][j-1] == '0') L[i][j] = L[i][j-1]; else L[i][j] = ++n2, posL[n2] = {i, j}; adj[U[i][j]].push_back(L[i][j]); } } while (bfs()) for (int i=1; i<=n1; i++) if (!_u[i] && dfs1(i)) ans++; cout << ans << "\n"; for (int u=1; u<=n1; u++) if (!_u[u]) dfs2(u); for (int u=1; u<=n1; u++) if (_u[u]){ if (vis[u]) cout << posL[_u[u]].first+1 << " " << posL[_u[u]].second << " DESNO\n"; else cout << posU[u].first << " " << posU[u].second+1 << " DOLJE\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...