알고 문제를 가끔씩 풀때마다 자괴감에 휩싸인다....
몇 개월만에 이토록 사람이 퇴화할 수 있다는 것을 여실히 느끼고 있따
실버 1인데.... 실버 1인데.....
생각보다 문제를 푸는 데에 시간이 꽤나 걸렸고
답은 맞았지만, 시간도 메모리도 모두 고려하지 않은 똥에 불과하다.
내가 만든 건 똥이다.
밑에 코드는 내 똥이다.
내똥칼라파워🌈💩🌈
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
static int R,C,T;
static int [][]map;
static int []dx={1,0,-1,0};
static int []dy={0,1,0,-1};
static class node{
int y,x;
node(int y,int x){
this.y=y;
this.x=x;
}
}
public static void main(String []args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R=Integer.parseInt(st.nextToken());
C=Integer.parseInt(st.nextToken());
T=Integer.parseInt(st.nextToken());
boolean [][]visit=new boolean[R][C];
map=new int[R][C];
for(int i=0;i<R;i++){
char []arr=br.readLine().toCharArray();
for(int j=0;j<C;j++){
if(arr[j]=='O'){
map[i][j]=1;
//System.out.println(i+" "+j);
}
}
}
int cnt=1;
//160000*200:32000000
while(cnt<T){
Queue<node>q=new ArrayDeque<>();
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
map[i][j]++;
if(map[i][j]==2) {
q.add(new node(i,j));
}
}
Arrays.fill(visit[i],false);
}
cnt++;
if(cnt>=T)break;
// 40000*4= 160000
while(!q.isEmpty()) {
node nd=q.poll();
int x=nd.x;
int y=nd.y;
map[y][x]=0;
visit[y][x]=true;
for(int k=0;k<4;k++){
int ny=y+dy[k];
int nx=x+dx[k];
if(ny<0||nx<0||ny>=R||nx>=C||visit[ny][nx]){
continue;
}
map[ny][nx]=0;
}
}
cnt++;
}
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(map[i][j]==0)System.out.print('.');
else System.out.print('O');
}
System.out.println();
}
}
}