This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
using namespace std;
long long a, b, q;
void solve(vector<vector<int> > &v){
long long x, y, col, vis[a + 1][b + 1];
memset(vis, 0, sizeof(vis));
pair<int, int> dir[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
cin >> x >> y >> col;
queue<pair<int, int> > q;
q.push({x, y});
while(!q.empty()){
pair<int, int> curr = q.front();
q.pop();
long long cx = curr.st, cy = curr.nd, currColor = v[cx][cy];
if(vis[cx][cy]) continue;
vis[cx][cy] = 1;
v[cx][cy] = col;
for (int i = 0; i < 4; i++)
{
if(!vis[cx + dir[i].first][cy + dir[i].second] && v[cx + dir[i].first][cy + dir[i].second] == currColor){
q.push({cx + dir[i].first, cy + dir[i].second});
}
}
}
}
int main(){
cin >> a >> b;
vector<vector<int> > d(a + 1, vector<int>(b + 1, 0));
for (int i = 1; i <= a; i++)
{
for (int j = 1; j <= b; j++)
{
cin >> d[i][j];
}
}
cin >> q;
while(q--){
solve(d);
}
for (int i = 1; i <= a; i++)
{
for (int j = 1; j <= b; j++)
{
cout << d[i][j] << " ";
}
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |