https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRJ8EKe48DFAUo
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Solution {
public static int N, M, K;
public static int[][] map;
public static List<Sell> list;
public static int[] dx = { 0, 0, 1, -1 };
public static int[] dy = { 1, -1, 0, 0 };
public static class Sell {
int x;
int y;
int day;
int state;
public Sell(int x, int y, int day, int state) {
super();
this.x = x;
this.y = y;
this.day = day;
this.state = state;
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int T = Integer.parseInt(st.nextToken());
for (int test_case = 1; test_case <= T; test_case++) {
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
map = new int[N + K][M + K];
list = new ArrayList<>();
for (int i = K / 2; i < K / 2 + N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = K / 2; j < K / 2 + M; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
if (map[i][j] > 0) {
list.add(new Sell(i, j, map[i][j], map[i][j] + 1));
}
}
}
for (int i = 1; i <= K; i++) {
list.sort((o1, o2) -> Integer.compare(o1.day, o2.day));
// 죽은세포 삭제
for (int j = list.size() - 1; j >= 0; j--) {
Sell s = list.get(j);
if (s.state - 1 + s.day == i) {
list.remove(j);
}
if (s.state == i) {
for (int k = 0; k < 4; k++) {
int nx = s.x + dx[k];
int ny = s.y + dy[k];
if(map[nx][ny] == 0) {
map[nx][ny] = s.day;
list.add(new Sell(nx,ny,s.day, s.day + i + 1));
}
}
}
}
}
System.out.println("#" + test_case + " " + list.size());
}
}
}'코딩테스트 > JAVA' 카테고리의 다른 글
| [SWEA JAVA] 2105. [모의 SW 역량테스트] 디저트 카페 (0) | 2024.08.27 |
|---|---|
| [SWEA JAVA] 2382. [모의 SW 역량테스트] 미생물 격리 (0) | 2024.08.27 |
| [SWEA JAVA] 7733번: 치즈 도둑 (0) | 2024.08.26 |
| [SWEA JAVA] 1873번: 상호의 배틀필드 (0) | 2024.08.23 |
| [SWEA JAVA] 1861번: 정사각형 방 (0) | 2024.08.22 |