#include <bits/stdc++.h>
using namespace std;
struct DSU{
vector<vector<array<int,2>>> par;
vector<vector<int>> sz;
DSU(int n, int m){
par.resize(n,vector<array<int,2>>(m));
sz.resize(n,vector<int>(m,1));
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j){
par[i][j]={i,j};
}
}
}
array<int,2> find(array<int,2> node){
if (par[node[0]][node[1]]==node) return node;
return par[node[0]][node[1]]=find(par[node[0]][node[1]]);
}
void merge(array<int,2> a, array<int,2> b){
a=find(a);
b=find(b);
if (a==b) return;
sz[a[0]][a[1]]+=sz[b[0]][b[1]];
sz[b[0]][b[1]]=0;
par[b[0]][b[1]]=a;
}
};
int main(){
int n,m;cin>>n>>m;
DSU dsu(n,m);
for (int i = 0; i < n+1; ++i)
{
string str;cin>>str;
if (i-1>=0 && i<n){
for (int j = 0; j < m; j++){
if (str[j]=='0'){
dsu.merge({i,j},{i-1,j});
}
}
}
}
for (int i = 0; i < n; i++){
string str;cin>>str;
for (int j = 1; j < m; j++){
if (str[j]=='0'){
dsu.merge({i,j},{i,j-1});
}
}
}
vector<int> LMAO;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (dsu.find({i,j})!=array<int,2>{i,j}) continue;
LMAO.push_back(dsu.sz[i][j]);
if (LMAO.back()==1) LMAO.pop_back();
}
}
sort(LMAO.begin(), LMAO.end());
if (LMAO.size()==1){
cout<<-LMAO.back()<<endl;
}
else cout<<"N/A"<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |