From ae47809ad199dca1d168b03eed174b035b761384 Mon Sep 17 00:00:00 2001 From: "YeJun, Jung" Date: Thu, 19 Feb 2026 13:51:20 +0900 Subject: [PATCH 1/4] feat: add swea p1238 solution --- problems/SWEA/p1238/Solution.java | 129 ++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 problems/SWEA/p1238/Solution.java diff --git a/problems/SWEA/p1238/Solution.java b/problems/SWEA/p1238/Solution.java new file mode 100644 index 0000000..81c63d6 --- /dev/null +++ b/problems/SWEA/p1238/Solution.java @@ -0,0 +1,129 @@ +/* + * (1238) [S/W 문제해결 기본] 10일차 - Contact + * https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15B1cKAKwCFAYD&categoryId=AV15B1cKAKwCFAYD&categoryType=CODE&problemTitle=1238&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1 + */ + +import java.io.*; +import java.util.*; + +/** + * SW Expert Academy - [S/W 문제해결 기본] 10일차 - Contact + * @author YeJun, Jung + * + * [분석] + * - BFS를 하는데, 마지막에 연락을 받는 노드들 중에서 가장 큰 숫자를 출력 + * + * [전략] + * - BFS 사용 + * - visited 배열을 사용해서 방문 처리(양방향 통신이 가능한 경우를 처리하기 위함) + * - 마지막에 연락을 받는 노드들 중에서 가장 큰 숫자를 출력 + */ +public class Solution { + static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer input; + + // ---------------------------------------------------------- + + public static void main(String[] args) throws IOException { + final int testCount = 10; + + for (int testCase = 1; testCase <= testCount; testCase++) { + new Solution(testCase).run(); + } + } + + // ---------------------------------------------------------- + + static final int MAX_NODE_LEN = 101; + + int testCase; + int answer; + int nodeLen; + int startNode; + List> graph; + boolean[] visited; + + public Solution(int testCase) { + this.testCase = testCase; + } + + public void run() throws IOException { + input(); + solve(); + print(); + } + + private void input() throws IOException { + getLine(); + nodeLen = Integer.parseInt(input.nextToken()); + startNode = Integer.parseInt(input.nextToken()); + + int fromNode, toNode; + graph = new ArrayList<>(MAX_NODE_LEN); + for (int cnt = 0; cnt < MAX_NODE_LEN; cnt++) { + graph.add(new ArrayList<>()); + } + + getLine(); + while (input.hasMoreTokens()) { + fromNode = Integer.parseInt(input.nextToken()); + toNode = Integer.parseInt(input.nextToken()); + + graph.get(fromNode).add(toNode); + } + } + + private void solve() { + visited = new boolean[MAX_NODE_LEN]; + Deque q = new ArrayDeque<>(); + answer = startNode; + int time = 0; + + q.offer(new Context(startNode, time)); + visited[startNode] = true; + + while (!q.isEmpty()) { + Context peek = q.poll(); + + if (time == peek.time) { + answer = Math.max(answer, peek.node); + } else if (time < peek.time) { + answer = peek.node; + time = peek.time; + } + + for (int node : graph.get(peek.node)) { + if (visited[node]) continue; + visited[node] = true; + + q.offer(new Context(node, peek.time + 1)); + } + } + } + + private void print() throws IOException { + writer.write("#" + testCase); + writer.write(" " + answer); + writer.write("\n"); + writer.flush(); + } + + // ---------------------------------------------------------- + + private static class Context { + int node; + int time; + + public Context(int node, int time) { + this.node = node; + this.time = time; + } + } + + // ---------------------------------------------------------- + + private static void getLine() throws IOException { + input = new StringTokenizer(reader.readLine().trim()); + } +} From f83ccc1e8c68e559b3fb9eb829d19739ed011586 Mon Sep 17 00:00:00 2001 From: "YeJun, Jung" Date: Thu, 19 Feb 2026 14:42:36 +0900 Subject: [PATCH 2/4] feat: swea p7733 solution --- problems/SWEA/p7733/Solution.java | 144 ++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 problems/SWEA/p7733/Solution.java diff --git a/problems/SWEA/p7733/Solution.java b/problems/SWEA/p7733/Solution.java new file mode 100644 index 0000000..e84f2e1 --- /dev/null +++ b/problems/SWEA/p7733/Solution.java @@ -0,0 +1,144 @@ +/* + * (7733) 치즈 도둑 + * https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWrDOdQqRCUDFARG&categoryId=AWrDOdQqRCUDFARG&categoryType=CODE&problemTitle=7733&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1 + */ + +import java.io.*; +import java.util.*; + +/** + * SW Expert Academy - 치즈 도둑 + * @author YeJun, Jung + * + * [분석] + * - 0...100일이 지나는 동안 매일 오늘 날짜에 해당하는 치즈가 삭제된다. + * - 0일 최초의 치즈는 하나의 덩어리이다. + * - 남아있는 치즈들이 상하좌우로 이웃해 있으면 하나의 그룹으로 본다. + * + * [전략] + * - 매일 해당 날짜의 치즈를 0으로 설정해 삭제 처리한다. + * - 삭제한 치즈의 개수를 카운트해서 프로그램의 조기 종료를 가능하게 한다. + * - 각 행렬 요소에 대해서 DFS를 하여 그룹의 개수를 센다. + * - DFS할때 상하좌우로 이웃한 요소로 가지를 펼친다. + */ +public class Solution { + static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer input; + + // ---------------------------------------------------------- + + public static void main(String[] args) throws IOException { + final int testCount = Integer.parseInt(reader.readLine().trim()); + + for (int testCase = 1; testCase <= testCount; testCase++) { + new Solution(testCase).run(); + } + } + + // ---------------------------------------------------------- + + static final int[] DIR_X = { 0, 0, -1, 1 }; + static final int[] DIR_Y = { -1, 1, 0, 0 }; + static final int DIR_LEN = 4; + + int testCase; + int answer; + int boardSize; + int[][] board; + boolean[][] visited; + + public Solution(int testCase) { + this.testCase = testCase; + } + + public void run() throws IOException { + input(); + solve(); + print(); + } + + private void input() throws IOException { + boardSize = Integer.parseInt(reader.readLine().trim()); + board = new int[boardSize][boardSize]; + + for (int y = 0; y < boardSize; y++) { + getLine(); + + for (int x = 0; x < boardSize; x++) { + board[y][x] = Integer.parseInt(input.nextToken()); + } + } + } + + private void solve() { + answer = 1; // 최초에 치즈는 하나의 덩어리이다. + int restBlocks = boardSize * boardSize; + + for (int day = 1; day <= 100 && restBlocks > 0; day++) { + restBlocks -= eating(day); + answer = Math.max(answer, countGroup()); + } + } + + private int eating(int num) { + int eatCount = 0; + + for (int y = 0; y < boardSize; y++) { + for (int x = 0; x < boardSize; x++) { + if (board[y][x] != num) continue; + + board[y][x] = 0; + eatCount++; + } + } + + return eatCount; + } + + private int countGroup() { + visited = new boolean[boardSize][boardSize]; + int result = 0; + + for (int y = 0; y < boardSize; y++) { + for (int x = 0; x < boardSize; x++) { + if (dfs(x, y)) result++; + } + } + + return result; + } + + private boolean dfs(int x, int y) { + if (board[y][x] == 0 || visited[y][x]) return false; + visited[y][x] = true; + + for (int dir = 0; dir < DIR_LEN; dir++) { + int nx = x + DIR_X[dir]; + int ny = y + DIR_Y[dir]; + + if (!isInsideBoard(nx, ny)) continue; + + dfs(nx, ny); + } + + return true; + } + + private boolean isInsideBoard(int x, int y) { + return x >= 0 && x < boardSize && y >= 0 && y < boardSize; + } + + private void print() throws IOException { + writer.write("#" + testCase); + writer.write(" " + answer); + writer.write("\n"); + writer.flush(); + } + + // ---------------------------------------------------------- + + private static void getLine() throws IOException { + input = new StringTokenizer(reader.readLine().trim()); + } +} From 2d9c3b51772951d4d9860461837fc5c77fe97d43 Mon Sep 17 00:00:00 2001 From: "YeJun, Jung" Date: Thu, 19 Feb 2026 15:13:29 +0900 Subject: [PATCH 3/4] feat: boj p1987 solution --- problems/baekjoon/p1987/Main.java | 107 ++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 problems/baekjoon/p1987/Main.java diff --git a/problems/baekjoon/p1987/Main.java b/problems/baekjoon/p1987/Main.java new file mode 100644 index 0000000..b85a6e1 --- /dev/null +++ b/problems/baekjoon/p1987/Main.java @@ -0,0 +1,107 @@ +/* + * (1987) 알파벳 + * https://www.acmicpc.net/problem/1987 + */ + +import java.io.*; +import java.util.*; + +/** + * Baekjoon - 알파벳 + * @author YeJun, Jung + * + * [분석] + * - 보드를 상하좌우로 이동하면서 방문한다. + * - 방문한 곳에 있는 알파벳을 기억해 두었다가, 해당 알파벳이 적힌 다른 타일을 방문할 수 없다. + * - 초기위치(0, 0)에 있는 알파벳에도 동일하게 적용된다. + * + * [전략] + * - DFS하면서 상하좌우 탐색한다. + * - visitied 배열에 알파벳을 키로 하여 방문여부를 저장한다. + * - 위치가 아닌 값을 이용해서 방문 처리하므로 DFS시 자식 노드 탐색 후 방문을 해제해 주어야 한다. + */ +public class Main { + static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer input; + + // ---------------------------------------------------------- + + public static void main(String[] args) throws IOException { + new Main().run(); + } + + // ---------------------------------------------------------- + + static final int[] DIR_X = { -1, 1, 0, 0 }; + static final int[] DIR_Y = { 0, 0, -1, 1 }; + static final int DIR_LEN = 4; + static final int ALPHABET_LEN = 'Z' - 'A' + 1; + + int answer; + int boardWidth; + int boardHeight; + char[][] board; + boolean[] visited; + + public void run() throws IOException { + input(); + solve(); + print(); + } + + private void input() throws IOException { + getLine(); + boardHeight = Integer.parseInt(input.nextToken()); + boardWidth = Integer.parseInt(input.nextToken()); + + board = new char[boardHeight][]; + + for (int y = 0; y < boardHeight; y++) { + board[y] = reader.readLine().trim().toCharArray(); + } + } + + private void solve() { + visited = new boolean[ALPHABET_LEN]; + + visited[board[0][0] - 'A'] = true; + answer = dfs(0, 0); + } + + private int dfs(int x, int y) { + int result = 0; + + for (int dir = 0; dir < DIR_LEN; dir++) { + int nx = x + DIR_X[dir]; + int ny = y + DIR_Y[dir]; + + if (!isInsideBoard(nx, ny)) continue; + + char ch = board[ny][nx]; + int key = ch - 'A'; + if (visited[key]) continue; + + visited[key] = true; + result = Math.max(result, dfs(nx, ny)); + visited[key] = false; + } + + return 1 + result; + } + + private boolean isInsideBoard(int x, int y) { + return x >= 0 && x < boardWidth && y >= 0 && y < boardHeight; + } + + private void print() throws IOException { + writer.write(answer + "\n"); + writer.flush(); + } + + // ---------------------------------------------------------- + + private static void getLine() throws IOException { + input = new StringTokenizer(reader.readLine().trim()); + } +} From 0338b68344d7cd660402f8e3515687a386983ef1 Mon Sep 17 00:00:00 2001 From: "YeJun, Jung" Date: Thu, 19 Feb 2026 16:57:57 +0900 Subject: [PATCH 4/4] feat: add swea p2636 solution --- problems/baekjoon/p2636/Main.java | 137 ++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 problems/baekjoon/p2636/Main.java diff --git a/problems/baekjoon/p2636/Main.java b/problems/baekjoon/p2636/Main.java new file mode 100644 index 0000000..7c5ae44 --- /dev/null +++ b/problems/baekjoon/p2636/Main.java @@ -0,0 +1,137 @@ +/* + * (2636) 치즈 + * https://www.acmicpc.net/problem/2636 + */ + +import java.io.*; +import java.util.*; + +/** + * Baekjoon - 치즈 + * @author YeJun, Jung + * + * [분석] + * - 주어진 보드에서 치즈 그룹의 가장자리가 1시간 마다 녹아 없어진다. + * - 치즈로 둘러쌓인 그룹 내부의 구멍의 가장자리는 녹지 않는다. + * + * [전략] + * - 보드를 입력받으면서 치즈의 개수를 센다. + * - 1턴을 지나면 다음 일이 일어난다. + * - setOutline(): 치즈 그룹의 외곽선을 찾는다. + * - 상하좌우로 이동하면서 DFS 한다. + * - 치즈를 발견하면 외곽선을 표시하고 해당 위치에 대해서는 더 이상 탐색하지 않는다. + * - meltOutline(): 찾아놓은 외곽선을 녹이고 남은 치즈의 개수를 업데이트 한다. + * - 'C'로 표시된 외곽선을 모두 찾아 없앤다. + * - 삭제한 치즈의 개수를 반환한다. + */ +public class Main { + static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer input; + + // ---------------------------------------------------------- + + public static void main(String[] args) throws IOException { + new Main().run(); + } + + // ---------------------------------------------------------- + + static final int[] DIR_X = { 0, 0, -1, 1 }; + static final int[] DIR_Y = { -1, 1, 0, 0 }; + static final int DIR_LEN = 4; + + int totalTime; + int tileLen; + int boardWidth; + int boardHeight; + char[][] board; + boolean[][] visited; + + public void run() throws IOException { + input(); + solve(); + print(); + } + + private void input() throws IOException { + getLine(); + boardHeight = Integer.parseInt(input.nextToken()); + boardWidth = Integer.parseInt(input.nextToken()); + + tileLen = 0; + board = new char[boardHeight][boardWidth]; + + for (int y = 0; y < boardHeight; y++) { + String line = reader.readLine().trim(); + + for (int x = 0; x < boardWidth; x++) { + board[y][x] = line.charAt(x * 2); + + if (board[y][x] == '1') ++tileLen; + } + } + } + + private void solve() { + totalTime = 0; + for (int nextTileLen = tileLen; nextTileLen > 0; totalTime++) { + tileLen = nextTileLen; + + setOutline(); + nextTileLen -= meltOutline(); + } + } + + private void setOutline() { + visited = new boolean[boardHeight][boardWidth]; + findOutline(0, 0); + } + + private void findOutline(int x, int y) { + for (int dir = 0; dir < DIR_LEN; dir++) { + int nx = x + DIR_X[dir]; + int ny = y + DIR_Y[dir]; + + if (!isInsideBoard(nx, ny) || visited[ny][nx]) continue; + visited[ny][nx] = true; + + if (board[ny][nx] == '1') { + board[ny][nx] = 'C'; + } else { + findOutline(nx, ny); + } + } + } + + private int meltOutline() { + int result = 0; + + for (int y = 0; y < boardHeight; y++) { + for (int x = 0; x < boardWidth; x++) { + if (board[y][x] != 'C') continue; + + board[y][x] = '0'; + result++; + } + } + + return result; + } + + private boolean isInsideBoard(int x, int y) { + return x >= 0 && x < boardWidth && y >= 0 && y < boardHeight; + } + + private void print() throws IOException { + writer.write(totalTime + "\n"); + writer.write(tileLen + "\n"); + writer.flush(); + } + + // ---------------------------------------------------------- + + private static void getLine() throws IOException { + input = new StringTokenizer(reader.readLine().trim()); + } +}