이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 + 2][b + 2];
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 + 2, vector<int>(b + 2, 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... |