이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define fr first
#define sc second
int n, m, q, c, aux[4] = {0,0,1,-1};
vector<vector<bool>> vis;
vector<vector<int>> v;
vector<pii> V;
void dfs(int x, int y) {
V.pb({x,y});
vis[x][y] = 1;
for(int i = 0; i < 4; i++) {
int a = x+aux[i], b = y+aux[3-i];
if(a >= 0 and b >= 0 and a < n and b < m and v[a][b] == v[x][y] and !vis[a][b])
dfs(a,b);
}
v[x][y] = c;
}
void bfs(int v1, int v2) {
queue<pii> fila;
fila.push({v1,v2});
vis[v1][v2] = 1;
while(!fila.empty()) {
auto [x,y] = fila.front();
fila.pop();
for(int i = 0; i < 4; i++) {
int a = x+aux[i], b = y+aux[3-i];
if(a >= 0 and b >= 0 and a < n and b < m and v[a][b] == v[x][y] and !vis[a][b])
fila.push({a,b}), vis[a][b] = 1;
}
v[x][y] = c;
}
}
int main() {
cin >> n >> m;
v.resize(n);
vis.resize(n);
for(int i = 0; i < n; i++) {
v[i].resize(m);
vis[i].resize(m);
for(int j = 0; j < m; j++)
cin >> v[i][j];
}
cin >> q;
while(q--) {
int a, b;
cin >> a >> b >> c;
bfs(a,b);
for(auto [x,y] : V) vis[x][y] = 0;
V.clear();
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cout << v[i][j] << " \n"[j==m-1];
}
# | 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... |