제출 #456280

#제출 시각아이디문제언어결과실행 시간메모리
456280grtSkandi (COCI20_skandi)C++17
0 / 110
277 ms524292 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[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(!vis[i] && 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...