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 ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
int n,m;
const int N=10019;
int a[N][N],vis[N][N];
void dfs (int x,int y,int c)
{
if(vis[x][y])return;
if(x==n+1||x==0||y==m+1||y==0)
{
return;
}
vis[x][y]=1;
if(a[x][y]==a[x-1][y])dfs(x-1,y,c);
if(a[x][y]==a[x+1][y])dfs(x+1,y,c);
if(a[x][y]==a[x][y+1])dfs(x,y+1,c);
if(a[x][y]==a[x][y-1])dfs(x,y-1,c);
a[x][y]=c;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
memset(a,-1,sizeof a);
for(int i=1;i<=n;i++)
{
for(int j=1;j<m+1;j++)
{
cin>>a[i][j];
}
}
int q;cin>>q;
while(q--)
{
int x,y,c;
cin>>x>>y>>c;
dfs(x,y,c);
memset(vis,0,sizeof vis);
}
for(int i=1;i<n+1;i++)
{
for(int j=1;j<m+1;j++)cout<<a[i][j]<<" ";
cout<<endl;
}
}
# | 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... |