Submission #456281

#TimeUsernameProblemLanguageResultExecution timeMemory
456281grtSkandi (COCI20_skandi)C++17
9 / 110
9 ms14420 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 = 510; 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; } 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; } int ans = 0; for(int i = 0; i < n * m; ++i) { ans += match[i] != -1; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...