반응형
내일 삼성 시험 대비겸 한번 푸러봣다..
근데 존나 문제더럽다. 2시간 30분가량 걸림 ㅈㅈ
내일 삼성시험 이런거 두개나오면 2솔은 절때못할듯
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class 모노미노미터 {
static int N;
static int Red[][] = new int[4][4];
static int Blue[][] = new int[4][6];
static int Green[][] = new int[6][4];
static int Order[][];
static int ans1;
static int ans2;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
N = Integer.parseInt(br.readLine());
Order = new int[N + 1][3];
for (int i = 1; i <= N; i++) {
st = new StringTokenizer(br.readLine());
Order[i][0] = Integer.parseInt(st.nextToken());
Order[i][1] = Integer.parseInt(st.nextToken());
Order[i][2] = Integer.parseInt(st.nextToken());
}
Solve();
System.out.println(ans1 + "\n" + ans2);
}
private static void Solve() {
for (int n = 1; n <= N; n++) {
int t = Order[n][0];
int y = Order[n][1];
int x = Order[n][2];
// System.out.println("no : "+n + t+" "+y+" "+x);
// System.out.println("이동전");
// System.out.println("블루");
// print(Blue);
// System.out.println("그린");
// print(Green);
// 이동
Move(t, y, x, n);
// System.out.println("이동후");
// System.out.println("블루");
// print(Blue);
// System.out.println("그린");
// print(Green);
// 제거
while (Delete()) {
}
// System.out.println("제거");
// System.out.println("블루");
// print(Blue);
// System.out.println("그린");
// print(Green);
// 특별한칸 제거
DeleteSpecial();
// System.out.println("특별판제거");
// System.out.println("블루");
// print(Blue);
// System.out.println("그린");
// print(Green);
// 제거
while (Delete()) {
}
// System.out.println("특별판제거후제거");
// System.out.println("블루");
// print(Blue);
// System.out.println("그린");
// print(Green);
}
getTile();
}
static int cmp[] = { 4, 5 };
private static void DeleteSpecial() {
// Blue
for (int i = 0; i <= 1; i++) {
boolean check = false;
for (int j = 0; j <= 3; j++) {
if (Green[i][j] != 0)
check = true;
}
if (check) {
for (int j = 0; j <= 3; j++) {
Green[cmp[i]][j] = 0;
}
}
}
// Green
for (int j = 0; j <= 1; j++) {
boolean check = false;
for (int i = 0; i <= 3; i++) {
if (Blue[i][j] != 0)
check = true;
}
if (check) {
for (int i = 0; i <= 3; i++) {
Blue[i][cmp[j]] = 0;
}
}
}
}
private static boolean Delete() {
DownBlue();
DownGreen();
boolean isExit = false;
// Green 확인
for (int i = 0; i <= 5; i++) {
int cnt = 0;
for (int j = 0; j <= 3; j++) {
if (Green[i][j] != 0)
cnt++;
}
if (cnt == 4) {
Arrays.fill(Green[i], 0);
ans1++;
isExit = true;
}
}
// Blue 확인
for (int j = 0; j <= 5; j++) {
int cnt = 0;
for (int i = 0; i <= 3; i++) {
if (Blue[i][j] != 0)
cnt++;
}
if (cnt == 4) {
for (int i = 0; i <= 3; i++) {
Blue[i][j] = 0;
}
ans1++;
isExit = true;
}
}
return isExit;
}
static int dy[] = { 1, -1, 0, 0 };
static int dx[] = { 0, 0, 1, -1 };
private static void DownGreen() {
boolean check[][] = new boolean[6][4];
int list[][];
for (int i = 5; i >= 0; i--) {
for (int j = 0; j <= 3; j++) {
if (check[i][j])
continue;
if (Green[i][j] == 0)
continue;
int n = Green[i][j];
list = new int[1][2];
list[0][0] = i;
list[0][1] = j;
for (int d = 0; d < 4; d++) {
int ny = i + dy[d];
int nx = j + dx[d];
if (ny < 0 || nx < 0 || ny > 5 || nx > 3)
continue;
if (Green[ny][nx] == n) {
list = new int[2][2];
list[0][0] = i;
list[0][1] = j;
list[1][0] = ny;
list[1][1] = nx;
break;
}
}
// Down 찾기
DownGreenProcess(list, check);
}
}
}
private static void DownGreenProcess(int[][] list, boolean[][] check) {
int n = Green[list[0][0]][list[0][1]];
for (int s = 0; s < list.length; s++) {
Green[list[s][0]][list[s][1]] = 0;
}
// 몇칸 내릴수 있는지
int len = 0;
for (int l = 1; l <= 5; l++) {
boolean p = true;
for (int s = 0; s < list.length; s++) {
int y = list[s][0] + l;
int x = list[s][1];
if (y > 5 || Green[y][x] != 0) {
p = false;
break;
}
}
if (p) {
len = l;
} else {
break;
}
}
for (int s = 0; s < list.length; s++) {
int y = list[s][0] + len;
int x = list[s][1];
Green[y][x] = n;
check[y][x] = true;
}
}
private static void DownBlue() {
boolean check[][] = new boolean[4][6];
int list[][];
for (int j = 5; j >= 0; j--) {
for (int i = 0; i <= 3; i++) {
if (check[i][j])
continue;
if (Blue[i][j] == 0)
continue;
int n = Blue[i][j];
list = new int[1][2];
list[0][0] = i;
list[0][1] = j;
for (int d = 0; d < 4; d++) {
int ny = i + dy[d];
int nx = j + dx[d];
if (ny < 0 || nx < 0 || ny > 3 || nx > 5)
continue;
if (Blue[ny][nx] == n) {
list = new int[2][2];
list[0][0] = i;
list[0][1] = j;
list[1][0] = ny;
list[1][1] = nx;
break;
}
}
// Down 찾기
DownBlueProcess(list, check);
}
}
}
private static void DownBlueProcess(int[][] list, boolean[][] check) {
int n = Blue[list[0][0]][list[0][1]];
for (int s = 0; s < list.length; s++) {
Blue[list[s][0]][list[s][1]] = 0;
}
// 몇칸 내릴수 있는지
int len = 0;
for (int l = 1; l <= 5; l++) {
boolean p = true;
for (int s = 0; s < list.length; s++) {
int y = list[s][0];
int x = list[s][1] + l;
if (x > 5 || Blue[y][x] != 0) {
p = false;
break;
}
}
if (p) {
len = l;
} else {
break;
}
}
for (int s = 0; s < list.length; s++) {
int y = list[s][0];
int x = list[s][1] + len;
Blue[y][x] = n;
check[y][x] = true;
}
}
private static void Move(int t, int y, int x, int n) {
if (t == 1) {
int[] b = moveBlue(y, x);
int[] g = moveGreen(y, x);
Blue[b[0]][b[1]] = n;
Green[g[0]][g[1]] = n;
} else if (t == 2) {
int[] b1 = moveBlue(y, x);
int[] g1 = moveGreen(y, x);
int[] g2 = moveGreen(y, x + 1);
int min = Math.min(g1[0], g2[0]);
g1[0] = min;
g2[0] = min;
Green[g1[0]][g1[1]] = n;
Green[g2[0]][g2[1]] = n;
Blue[b1[0]][b1[1]] = n;
Blue[b1[0]][b1[1]-1] = n;
} else {
int[] b1 = moveBlue(y, x);
int[] b2 = moveBlue(y + 1, x);
int[] g1 = moveGreen(y, x);
int min = Math.min(b1[1], b2[1]);
b1[1] = min;
b2[1] = min;
Green[g1[0]][g1[1]] = n;
Green[g1[0]-1][g1[1]] = n;
Blue[b1[0]][b1[1]] = n;
Blue[b2[0]][b2[1]] = n;
}
}
/*
* blue는 y고정 x만 움직임
*/
private static int[] moveBlue(int y, int x) {
int b[] = new int[2];
b[0] = y;
for (int j = 0; j <= 5; j++) {
if (Blue[y][j] == 0)
continue;
b[1] = j - 1;
return b;
}
b[1] = 5;
return b;
}
/*
* blue는 y고정 x만 움직임
*/
private static int[] moveGreen(int y, int x) {
int g[] = new int[2];
g[1] = x;
for (int i = 0; i <= 5; i++) {
if (Green[i][x] == 0)
continue;
g[0] = i - 1;
return g;
}
g[0] = 5;
return g;
}
private static void getTile() {
for (int i = 0; i < Blue.length; i++) {
for (int j = 0; j < Blue[0].length; j++) {
if (Blue[i][j] != 0)
ans2++;
}
}
for (int i = 0; i < Green.length; i++) {
for (int j = 0; j < Green[0].length; j++) {
if (Green[i][j] != 0)
ans2++;
}
}
}
private static void print(int map[][]) {
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[0].length; j++) {
System.out.print(map[i][j]);
}
System.out.println();
}
System.out.println();
}
}
반응형
'ProgramSoliving' 카테고리의 다른 글
프로그래머스 : 전화번호목록 (0) | 2020.12.11 |
---|---|
프로그래머스 : 완주하지 못한 선수 (0) | 2020.12.10 |
백준 : 19237 어른상어 java (0) | 2020.10.08 |
백준 : 19238 스타트 택시 (JAVA) (0) | 2020.10.07 |
백준 : 13549 (0) | 2020.09.15 |