Labyrinth
http://codeforces.com/problemset/problem/1064/D
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<string> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #pragma GCC optimize(2) 10 using namespace std; 11 12 int n,m; 13 char map[2005][2005]; 14 struct Num{ 15 int L,R; 16 }book[2005][2005]; 17 int r,c,L,R; 18 struct sair{ 19 int x,y,L,R; 20 }; 21 int dir[4][2]={0,-1,-1,0,0,1,1,0};//R,D,L,U 22 23 void bfs(){ 24 queue<sair>Q; 25 sair s,e; 26 s.x=r,s.y=c,s.L=L,s.R=R; 27 Q.push(s); 28 book[s.x][s.y].L=L; 29 book[s.x][s.y].R=R; 30 while(!Q.empty()){ 31 s=Q.front(); 32 Q.pop(); 33 for(int i=0;i<4;i++){ 34 e.x=s.x+dir[i][0]; 35 e.y=s.y+dir[i][1]; 36 if(e.x>=0&&e.x<n&&e.y>=0&&e.y<m&&map[e.x][e.y]!='*'){ 37 e.L=s.L; 38 e.R=s.R; 39 if(i==2){ 40 e.R--; 41 if(e.R<0) continue; 42 } 43 else if(i==0){ 44 e.L--; 45 if(e.L<0) continue; 46 } 47 if(book[e.x][e.y].L<e.L||book[e.x][e.y].R<e.R){ 48 book[e.x][e.y].L=max(book[e.x][e.y].L,e.L); 49 book[e.x][e.y].R=max(book[e.x][e.y].R,e.R); 50 Q.push(e); 51 } 52 53 } 54 } 55 } 56 } 57 58 int main(){ 59 cin>>n>>m; 60 cin>>r>>c; 61 cin>>L>>R; 62 for(int i=0;i<=2000;i++){ 63 for(int j=0;j<=2000;j++){ 64 book[i][j].L=book[i][j].R=-1; 65 } 66 } 67 for(int i=0;i<n;i++){ 68 cin>>map[i]; 69 } 70 r--,c--; 71 bfs(); 72 int ans=0; 73 for(int i=0;i<n;i++){ 74 for(int j=0;j<m;j++){ 75 if(book[i][j].L!=-1||book[i][j].R!=-1){ 76 ans++; 77 } 78 } 79 } 80 cout<<ans<<endl; 81 }