이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=30;
vector<pair<int,int>>V[LIM][LIM];
int odw[LIM][LIM], ile=0, kraw[LIM][LIM];
void DFS(int a, int b) {
++ile;
odw[a][b]=1;
for(auto i : V[a][b]) if(!odw[i.st][i.nd]) DFS(i.st, i.nd);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
string s;
cin >> s;
rep(j, m) {
if(s[j]=='0') {
++kraw[0][j];
}
}
rep(i, n-1) {
cin >> s;
rep(j, m) {
if(s[j]=='0') {
V[i][j].pb({i+1, j});
V[i+1][j].pb({i, j});
++kraw[i][j];
++kraw[i+1][j];
}
}
}
cin >> s;
rep(j, m) {
if(s[j]=='0') {
++kraw[n-1][j];
}
}
rep(i, n) {
cin >> s;
if(s[0]=='0') {
++kraw[i][0];
}
rep(j, m-1) {
if(s[j+1]=='0') {
V[i][j+1].pb({i, j});
V[i][j].pb({i, j+1});
++kraw[i][j];
++kraw[i][j+1];
}
}
if(s[m]=='0') {
++kraw[i][m-1];
}
}
vector<int>spojne;
rep(i, n) rep(j, m) if(!odw[i][j] && kraw[i][j]==2) {
ile=0;
DFS(i, j);
spojne.pb(ile);
}
cout << -spojne[0] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |