Submission #456288

#TimeUsernameProblemLanguageResultExecution timeMemory
456288grtSkandi (COCI20_skandi)C++17
110 / 110
201 ms60452 KiB
#include <bits/stdc++.h> #define ST first #define ND second #define PB push_back using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 1010; int n, m; char t[nax][nax]; int lft[nax][nax], up[nax][nax]; vi V[nax * nax * 2]; bool vis[nax * nax * 2]; int match[nax * nax * 2]; bool aug(int x) { vis[x] = true; for(int nbh : V[x]) if(match[nbh] == -1) { match[x] = nbh; match[nbh] = x; return true; } for(int nbh : V[x]) if(!vis[match[nbh]]) { if(aug(match[nbh])) { match[x] = nbh; match[nbh] = x; return true; } } return false; } vi ans; void dfs(int x) { vis[x] = true; for(int nbh : V[x]) if(!vis[nbh]) { ans.PB(nbh); vis[nbh] = true; dfs(match[nbh]); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { cin >> t[i][j]; if(t[i][j] == '1') { lft[i][j] = i * m + j; up[i][j] = i * m + j; } else { lft[i][j] = lft[i][j - 1]; up[i][j] = up[i - 1][j]; V[up[i][j]].PB(lft[i][j] + n * m); V[lft[i][j] + n * m].PB(up[i][j]); } } } for(int i = 0; i < n * m * 2; ++i) match[i] = -1; while(true) { for(int i = 0; i < n * m * 2; ++i) vis[i] = false; bool any = false; for(int i = 0; i < n * m * 2; ++i) { if(match[i] == -1 && aug(i)) any = true; } if(!any) break; } for(int i = 0; i < n *m * 2; ++i) vis[i] = false; for(int i = 0; i < n * m * 2; ++i) { if(!vis[i] && match[i] == -1) { dfs(i); } } for(int i = 0; i < n * m * 2; ++i) { if(!vis[i]) dfs(i); } cout << (int)ans.size() << "\n"; for(int x : ans) { bool bit = x < n * m; x %= n * m; cout << x / m + 1 << " " << x % m + 1<< " " << ((1-bit) ? "DESNO" : "DOLJE") << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...