diff --git a/week14/clean2001/.gitkeep b/week14/clean2001/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week14/clean2001/B14890.java b/week14/clean2001/B14890.java new file mode 100644 index 0000000..35d5fad --- /dev/null +++ b/week14/clean2001/B14890.java @@ -0,0 +1,155 @@ +import java.io.*; +import java.util.*; +// 경사로 +class Main { + static int N, L; + static int[][] map; + static boolean[][] isHeel; + 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()); + N = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + + map = new int[N][N]; + isHeel = new boolean[N][N]; + + for(int i=0; i 1) { + flag = false; break; // 이 길은 안됨 + } + + if(diff == 1 && map[i][j] < map[i][j+1]) { // 왼쪽 검사 + int h = map[i][j]; + for(int d = 0; d map[i][j+1]) { // 오른쪽 검사 + + int h = map[i][j+1]; + for(int d=1; d<=L; ++d) { + int nx = j + d; + if(nx >= N || rowHeel[nx] || isHeel[i][nx] || h != map[i][nx]) { + flag = false; + break; // 이 길은 안됨 + } + } + + if(flag) { + for(int d=1; d<=L; ++d) { + rowHeel[j+d] = true; + } + } else break; + } + } + + // + if(flag) { +// System.out.println("가로: " + i); + ans++; + for(int j=0; j 1) { + flag = false; break; // 이 길은 안됨 + } + + if(diff == 1 && map[j][i] < map[j+1][i]) { // 위쪽 검사 + int h = map[j][i]; + for(int d = 0; d map[j+1][i]) { // 아래쪽 검사 + + + + int h = map[j+1][i]; + for(int d=1; d<=L; ++d) { + int ny = j + d; + + if(ny >= N || rowHeel[ny] || isHeel[ny][i] || h != map[ny][i]) { + + flag = false; + break; // 이 길은 안됨 + } + } + + if(flag) { + for(int d=1; d<=L; ++d) { + rowHeel[j+d] = true; + } + } else break; + } + } + + // + if(flag) { +// System.out.println("세로: " + i); + ans++; + for(int j=0; j map = new HashMap<>(); + for(int i=0; i prefix.length()) { + prefix = curPrefix; + idx1 = map.get(arr[i]); + idx2 = map.get(arr[i+1]); + } else if(curPrefix.length() == prefix.length() && !prefix.equals(curPrefix)) { + // 길이가 같으면 원래 인덱스가 더 작은 것을 선택 + int tempIdx1 = map.get(arr[i]); + int tempIdx2 = map.get(arr[i+1]); + + int[] tempArr = {idx1, idx2, tempIdx1, tempIdx2}; + Arrays.sort(tempArr); + + + if(tempArr[0] == tempIdx1 || tempArr[0] == tempIdx2) { + idx1 = tempIdx1; + idx2 = tempIdx2; + prefix = curPrefix; + } + } + } + + int cnt = 0; +// System.out.println(prefix); + for(int i=0; i