Submission #431942

#TimeUsernameProblemLanguageResultExecution timeMemory
431942DaktoGame (eJOI20_game)C++17
20 / 100
1 ms292 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector<vector<int>> g(n*m); vector<int> cnt(n*m); for(int i=0; i<=n; i++){ string s; cin>>s; if(i==0 || i==n){ for(int j=0; j<m; j++){ if(s[j]=='0') cnt[(i==0?0:n-1)*m+j]++; } } else{ for(int j=0; j<m; j++){ if(s[j]=='0'){ g[(i-1)*m+j].push_back(i*m+j); g[i*m+j].push_back((i-1)*m+j); } } } } for(int i=0; i<n; i++){ string s; cin>>s; for(int j=1; j<n; j++){ if(s[j]=='0'){ g[i*m+j].push_back(i*m+j-1); g[i*m+j-1].push_back(i*m+j); } } } vector<bool> seen(n*m,0); vector<int> comp; for(int i=0; i<n*m; i++){ if(!seen[i] && (g[i].size() || cnt[i])){ int sz=0; queue<int> q; q.push(i); while(!q.empty()){ auto t=q.front(); q.pop(); if(seen[t]) continue; sz++; seen[t]=1; for(int j:g[t]) if(!seen[j]) q.push(j); } comp.push_back(sz); } } sort(comp.begin(),comp.end()); int res=0; int p=-1; for(int i:comp){ res+=p*i; p*=-1; } cout<<res<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...