Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- int n,m,kolku;
- int dr[1005] = {-1, 0, +1, 0};
- int dc[1005] = {0, +1, 0, -1};
- int vis[1005][1005];
- int s[10];
- int cnt[20];
- char mat[1005][1005];
- //koj polinja gi ima koj vo sekoj moment
- queue<int>Q[20];
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin>>n>>m>>kolku;
- for(int i=0;i<kolku;i++)
- {
- cin>>s[i];
- }
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- cin>>mat[i][j];
- vis[i][j]=false;
- }
- }
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- if(isdigit(mat[i][j]))
- {
- int x=mat[i][j]-'0';
- Q[x-1].push(i);
- Q[x-1].push(j);
- Q[x-1].push(s[x-1]);
- cnt[x-1]++;
- vis[i][j] = true;
- }
- }
- }
- while(true)
- {
- bool ok=false;
- for(int i=0;i<kolku;i++)
- {
- if(!Q[i].empty())
- {
- ok=true;
- break;
- }
- }
- if(ok==false)
- {
- break;
- }
- for(int i=0;i<kolku;i++)
- {
- vector<pair<int,int>>v;
- while(!Q[i].empty())
- {
- int r=Q[i].front();
- Q[i].pop();
- int c=Q[i].front();
- Q[i].pop();
- int d=Q[i].front();
- Q[i].pop();
- // cout << i + 1 << " " << r + 1 << " " << c + 1 << " " << d <<endl;
- for(int x = 0;x<4;x++)
- {
- int nr= r+dr[x];
- int nc= c+dc[x];
- if(nr<n && nr>=0 && nc<m && nc>=0 && vis[nr][nc]==false && mat[nr][nc]=='.' && d - 1 >= 0)
- {
- Q[i].push(nr);
- Q[i].push(nc);
- Q[i].push(d-1);
- v.push_back({nr,nc});
- vis[nr][nc]=true;
- cnt[i]++;
- }
- }
- }
- for(int j=0;j<v.size();j++)
- {
- Q[i].push(v[j].first);
- Q[i].push(v[j].second);
- Q[i].push(s[i]);
- }
- }
- }
- for(int i=0;i<kolku;i++)
- {
- cout<<cnt[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement