#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define endl "\n"
#define ll long long
#define N 200005
int var[N],renk[N];
int n,m;
void bfs(int x,int co,int mor){
queue<int> q;
q.push(x);
while(q.size()){
int a=q.front();q.pop();
if(var[a])continue;
var[a]=1;
renk[a]=mor;
if((a-1)%m&&var[a-1]==0&&renk[a-1]==co){q.push(a-1);}
if(a%m&&var[a+1]==0&&renk[a+1]==co){q.push(a+1);}
if(a-m>0&&var[a-m]==0&&renk[a-m]==co){q.push(a-m);}
if(a+m<=n*m&&var[a+m]==0&&renk[a+m]==co){q.push(a+m);}
}
}
int main(){
lalala;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int x=(i-1)*m+j;
cin>>renk[x];
}
}
int q;cin>>q;
while(q--){
int x,yyy,mor;cin>>x>>yyy>>mor;
x=(x-1)*m+yyy;
bfs(x,renk[x],mor);
memset(var,0,sizeof(var));
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int x=(i-1)*m+j;
cout<<renk[x]<<" ";
}cout<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
61 ms |
1224 KB |
Output is correct |
4 |
Correct |
82 ms |
1196 KB |
Output is correct |
5 |
Correct |
348 ms |
1352 KB |
Output is correct |
6 |
Correct |
457 ms |
1188 KB |
Output is correct |
7 |
Correct |
1 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1171 ms |
1292 KB |
Output is correct |
2 |
Correct |
1310 ms |
2788 KB |
Output is correct |
3 |
Execution timed out |
3042 ms |
2988 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3049 ms |
2000 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
777 ms |
1920 KB |
Output is correct |
2 |
Execution timed out |
3028 ms |
3140 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |