이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int dir[][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
const int N = 1025;
int n, m, c, sz[N][N];
pair<int, int> p[N][N];
char a[N][N];
pair<int, int> P(int i, int j) {
int ni = p[i][j].first;
int nj = p[i][j].second;
if(ni == nj && nj == 0)
return make_pair(i, j);
return p[i][j] = P(ni, nj);
}
void U(pair<int, int> a, pair<int, int> b) {
a = P(a.first, a.second);
b = P(b.first, b.second);
if(a != b) {
sz[b.first][b.second] += sz[a.first][a.second];
p[a.first][a.second] = b;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int wrt = 0, oi = 0, oj = 0;
cin >> n >> m >> c;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cin >> a[i][j];
sz[i][j] = 1;
if(a[i][j] == '.') {
++wrt;
oi = i;
oj = j;
}
}
}
int fp = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
if(a[i][j] == '.') {
if(j < m && a[i][j + 1] == '.') U({i, j}, {i, j + 1});
if(i < n && a[i + 1][j] == '.') U({i, j}, {i + 1, j});
}
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
int cc = 0;
if(a[i][j] == '.') {
for(int x = 0; x < 4; ++x) {
int ni = i + dir[x][0];
int nj = j + dir[x][1];
if(a[ni][nj] == '.') ++cc;
}
}
if(cc == 1) ++fp;
// if(cc == 1) {
// cout << "X";
// } else {
// cout << " ";
// }
}
// cout << "\n";
}
// cout << "\n";
// for(int i = 1; i <= n; ++i) {
// for(int j = 1; j <= m; ++j) {
// if(a[i][j] == '.')
// cout << (P(i, j).first + P(i, j).second) % 10 << "";
// else
// cout << " ";
// }
// cout << "\n";
// }
cout << (wrt == sz[oi][oj]) << " " << fp << endl;
return 0;
}
# | 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... |
# | 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... |