| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 512 MB | 41663 | 23364 | 15843 | 55.160% |
미세먼지를 제거하기 위해 구사과는 공기청정기를 설치하려고 한다. 공기청정기의 성능을 테스트하기 위해 구사과는 집을 크기가 R×C인 격자판으로 나타냈고, 1×1 크기의 칸으로 나눴다. 구사과는 뛰어난 코딩 실력을 이용해 각 칸 (r, c)에 있는 미세먼지의 양을 실시간으로 모니터링하는 시스템을 개발했다. (r, c)는 r행 c열을 의미한다.

공기청정기는 항상 1번 열에 설치되어 있고, 크기는 두 행을 차지한다. 공기청정기가 설치되어 있지 않은 칸에는 미세먼지가 있고, (r, c)에 있는 미세먼지의 양은 Ar,c이다.
1초 동안 아래 적힌 일이 순서대로 일어난다.
1. 미세먼지가 확산된다. 확산은 미세먼지가 있는 모든 칸에서 동시에 일어난다.


첫째 줄에 R, C, T (6 ≤ R, C ≤ 50, 1 ≤ T ≤ 1,000) 가 주어진다.
둘째 줄부터 R개의 줄에 Ar,c (-1 ≤ Ar,c ≤ 1,000)가 주어진다. 공기청정기가 설치된 곳은 Ar,c가 -1이고, 나머지 값은 미세먼지의 양이다. -1은 2번 위아래로 붙어져 있고, 가장 윗 행, 아랫 행과 두 칸이상 떨어져 있다.
첫째 줄에 T초가 지난 후 구사과 방에 남아있는 미세먼지의 양을 출력한다.
예제 입력 1
7 8 1
0 0 0 0 0 0 0 9
0 0 0 0 3 0 0 8
-1 0 5 0 0 0 22 0
-1 8 0 0 0 0 0 0
0 0 0 0 0 10 43 0
0 0 5 0 15 0 0 0
0 0 40 0 0 0 20 0
예제 출력 1
188

public class Simulator_17144 {
public static int R,C,T;
public static int[][] arr;
public static int[][] copy_arr;
public static ArrayList<Integer> device; // 공기청정기 위치
public static int[] dx = {0,-1,0,1};
public static int[] dy = {-1,0,1,0};
public static void main(String[] args) throws IOException{
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());
arr = new int[R][C];
copy_arr = new int[R][C];
device = new ArrayList<Integer>();
for (int i = 0; i < R; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < C; j++) {
arr[i][j] = Integer.parseInt(st.nextToken());
copy_arr[i][j] = arr[i][j];
if(arr[i][j]==-1) device.add(i); // 공기청정기 1열에 있고 행을 파악하기 위함
}
}
// 초마다 미세먼지 확산 => 함수호출
for(int i=0; i<T; i++) {
spread();
clean_top(device.get(0));
clean_bottom(device.get(1));
copy_arr_A();
}
int sum = 0;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
//System.out.print(arr[i][j]+" ");
sum+=arr[i][j];
}
//System.out.println();
}
System.out.println(sum+2);
}
public static void spread() {
for(int i=0; i<R; i++) {
for(int j=0; j<C; j++) {
if(arr[i][j]>0) { // 미세먼지가 있으면
int spread_dust = arr[i][j]/5;
for(int t=0; t<4; t++) {
int xx = i+dx[t];
int yy = j+dy[t];
if(xx>=0 && xx<R && yy>=0 && yy<C && arr[xx][yy]!=-1) {
copy_arr[xx][yy]+=spread_dust; // 새로운 곳에 확산
copy_arr[i][j]-=spread_dust; //기존 미세먼지 제거
}
}
}
}
}
}
public static void clean_top(int pos) {
for(int i=pos; i>0; i--) copy_arr[i][0] = copy_arr[i-1][0];
for(int i=0; i<C-1; i++) copy_arr[0][i] = copy_arr[0][i+1];
for(int i=0; i<pos; i++) copy_arr[i][C-1] = copy_arr[i+1][C-1];
for(int i=C-1; i>0; i--) copy_arr[pos][i] = copy_arr[pos][i-1];
copy_arr[pos][0]=-1;
copy_arr[pos][1]=0;
}
public static void clean_bottom(int pos) {
for(int i=pos; i<R-1; i++) copy_arr[i][0] = copy_arr[i+1][0];
for(int i=0; i<C-1; i++) copy_arr[R-1][i] = copy_arr[R-1][i+1];
for(int i=R-1; i>=pos; i--) copy_arr[i][C-1] = copy_arr[i-1][C-1];
for(int i=C-1; i>0; i--) copy_arr[pos][i] = copy_arr[pos][i-1];
copy_arr[pos][0]=-1;
copy_arr[pos][1]=0;
}
public static void copy_arr_A() {
for(int i=0; i<R; i++) {
for(int j=0; j<C; j++) {
arr[i][j] = copy_arr[i][j];
}
}
}
}
