이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n, m, ans;
string s[2005];
queue<pair<int, int> >q;
bool us[2005][2005];
pair<int, int>dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void fun()
{
cin>>n>>m;
for(int i = 0; i < n; i++)
{
cin>>s[i];
}
for(int i = 1; i < n - 1; i++)
{
for(int j = 1; j < m - 1; j++)
{
if(!us[i][j] && s[i][j] == '.')
{
vector<int>xx(n + 1, 0), yy(m + 1, 0);
q.push({i, j});
bool boo = 0;
int c = 0;
while(!q.empty())
{
int x = q.front().first,
y = q.front().second;
q.pop();
us[x][y] = 1;
bool goo = 0;
for(int k = 0; k < 4; k++)
{
if(x + dir[k].first > n - 1
|| x + dir[k].first < 0
|| y + dir[k].second > m - 1
|| y + dir[k].second < 0)
{
boo = 1;
continue;
}
if(s[x + dir[k].first][y + dir[k].second] == '#')
goo = 1;
else if(!us[x + dir[k].first][y + dir[k].second] &&
s[x + dir[k].first][y + dir[k].second] == '.')
q.push({x + dir[k].first, y + dir[k].second}),
us[x + dir[k].first][y + dir[k].second] = 1;
}
if(goo)
xx[x]++, yy[y]++, c++;
}
if(boo)
continue;
if(c == 1)
{
ans++;
continue;
}
int l = 0;
while(l < n - 1 && xx[l] == 0)
l++;
if(xx[l] != 1 || xx[l + 1] != 2)
continue;
l++;
while(l < n - 1 && xx[l] == 2)
l++;
if(xx[l] != 1 || (l != n - 1 && xx[l + 1] != 0))
continue;
l = 0;
while(l < m - 1 && yy[l] == 0)
l++;
if(yy[l] != 1 || yy[l + 1] != 2)
continue;
l++;
while(l < m - 1 && yy[l] == 2)
l++;
if(yy[l] != 1 || (l != m - 1 && yy[l + 1] != 0))
continue;
ans++;
}
}
}
cout<<ans;
}
int main()
{
ll ttt = 1;
//cin>>ttt;
while(ttt--)
fun();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |