Submission #303411

#TimeUsernameProblemLanguageResultExecution timeMemory
303411pit4hDango Maker (JOI18_dango_maker)C++14
0 / 100
1 ms384 KiB
#include<bits/stdc++.h> using namespace std; const int N = 3001; int matched[N * N], vis[N * N]; int iter; bool connected[N * N]; bool match(int x, vector<vector<int>>& g) { vis[x] = iter; for(int i: g[x]) { if(matched[i] == -1) { matched[i] = x; return true; } } for(int i: g[x]) { if(vis[i] != iter && match(matched[i], g)) { matched[i] = x; return true; } } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; vector<string> tab(n); for(int i=0; i<n; ++i) { cin>>tab[i]; } vector<vector<bool>> horiz(n, vector<bool>(m)), vert(n, vector<bool>(m)); for(int i=0; i<n; ++i) { // left - right for(int j=0; j+2<m; ++j) { if(tab[i][j] == 'R' && tab[i][j+1] == 'G' && tab[i][j+2] == 'W') { vert[i][j] = 1; } } } vector<vector<int>> rep(n, vector<int>(m)); int nr = 0; for(int i=0; i+2<n; ++i) { // top - bottom for(int j=0; j<m; ++j) { if(tab[i][j] == 'R' && tab[i+1][j] == 'G' && tab[i+2][j] == 'W') { horiz[i][j] = 1; rep[i][j] = nr; nr++; } } } vector<vector<int>> g; for(int i=0; i<n; ++i) { for(int j=0; j<m; ++j) { if(vert[i][j]) { g.push_back({}); if(horiz[i][j]) { g.back().push_back(rep[i][j]); connected[rep[i][j]] = 1; } if(i-1>=0 && j+1<n && horiz[i-1][j+1]) { g.back().push_back(rep[i-1][j+1]); connected[rep[i-1][j+1]] = 1; } if(i-2>=0 && j+2<n && horiz[i-2][j+2]) { g.back().push_back(rep[i-2][j+2]); connected[rep[i-2][j+2]] = 1; } } } } for(int i=0; i<nr; ++i) { matched[i] = -1; } int sz = g.size(); int ans = 0; for(int i=0; i<sz; ++i) { iter++; match(i, g); if(g[i].empty()) ans++; } for(int i=0; i<nr; ++i) { if(matched[i] != -1 || !connected[i]) ans++; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...