Atcoder ABC 197 - B - Visibility
/*
Count '.' - from the same row and column and count each
Finally, subtract 3, as (x, y) repeated like 3 times
*/
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
const int high=1000+5;
char adj[high][high];
int main()
{
int i, j, h, w, x, y;
cin >> h >> w >> x >> y;
for(i=0; i<h; i++)
{
for(j=0; j<w; j++)
{
cin >> adj[i][j];
}
}
int cnt=0;
x--; y--;
for(i=x; i<h; i++) //row - down
{
if(adj[i][y]=='#') break;
cnt+=1;
}
for(i=x; i>=0; i--) // row - up
{
if(adj[i][y]=='#') break;
cnt+=1;
}
for(j=y; j<w; j++) // column - right
{
if(adj[x][j]=='#') break;
cnt+=1;
}
for(j=y; j>=0; j--) // column - left
{
if(adj[x][j]=='#') break;
cnt+=1;
}
cnt -= 3;
cout << cnt << "\n";
return 0;
}
Comments
Post a Comment