Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string s[1005];
- int a[1005][1005];
- int xs[4] = { 0 , +1 , 0 , -1 };
- int ys[4] = { +1 , 0 , -1 , 0 };
- int main()
- {
- int n,m,k;
- cin>>n>>m>>k;
- for (int i=1 ; i<=n ; i++)
- { cin>>s[i]; s[i] = "#"+s[i]+"#"; }
- for (int i=0 ; i<m+1 ; i++) s[0].push_back('#') , s[n+1].push_back('#');
- int ans = 0;
- queue<pair<int,int>> q;
- for (int i=0 ;i<k ; i++)
- {
- int x,y; cin>>x>>y;
- s[x][y] = '#';
- q.push( make_pair( x,y ) );
- }
- while ( q.empty() == false )
- {
- pair<int,int> p = q.front() ; q.pop();
- for (int i=0 ; i<4 ; i++)
- {
- int x = p.first + xs[i] , y = p.second + ys[i];
- if ( s[x][y] != '#' )
- {
- a[x][y] = a[p.first][p.second] + 1;
- s[x][y] = '#';
- ans += a[x][y];
- q.push( make_pair( x , y ) );
- }
- }
- }
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement