From 81b69f6b4488579c09c40bbb78984c878997379c Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 13 Feb 2025 14:27:59 +0900 Subject: [PATCH] =?UTF-8?q?[20250213]=20BOJ=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=20=ED=86=B1=EB=8B=88=EB=B0=94=ED=80=B4(2)=20/=20=EC=84=A4?= =?UTF-8?q?=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\213\210\353\260\224\355\200\264(2).md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "Seol-JY/202502/13 BOJ G5 \355\206\261\353\213\210\353\260\224\355\200\264(2).md" diff --git "a/Seol-JY/202502/13 BOJ G5 \355\206\261\353\213\210\353\260\224\355\200\264(2).md" "b/Seol-JY/202502/13 BOJ G5 \355\206\261\353\213\210\353\260\224\355\200\264(2).md" new file mode 100644 index 00000000..72b78773 --- /dev/null +++ "b/Seol-JY/202502/13 BOJ G5 \355\206\261\353\213\210\353\260\224\355\200\264(2).md" @@ -0,0 +1,75 @@ +```java +import java.io.*; +import java.util.*; +public class Main { + private static int count = 0; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int T = Integer.parseInt(br.readLine()); + int[] arr = new int[T]; + + for (int i = 0; i < T; i++) { + arr[i] = Integer.parseInt(br.readLine(), 2); + } + + int K = Integer.parseInt(br.readLine()); + + for (int i = 0; i < K; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int index = Integer.parseInt(st.nextToken()) - 1; + int direction = Integer.parseInt(st.nextToken()); + + int[] turns = new int[T]; + turns[index] = direction; + + for (int j = index - 1; j >= 0; j--) { + if (needTurn(arr[j], arr[j+1])) { + turns[j] = -turns[j+1]; + } else { + break; + } + } + for (int j = index + 1; j < T; j++) { + if (needTurn(arr[j-1], arr[j])) { + turns[j] = -turns[j-1]; + } else { + break; + } + } + + for (int j = 0; j < T; j++) { + if (turns[j] == 1) { + arr[j] = clockwise(arr[j]); + } else if (turns[j] == -1) { + arr[j] = antiClockwise(arr[j]); + } + } + } + int answer = 0; + for (int i = 0; i < T; i++) { + if ((arr[i] & 128) == 128) { + answer++; + } + } + System.out.println(answer); + } + + + // 회전 여부 결정 + private static boolean needTurn(Integer left, Integer right) { + return ((left & 32) == 32) != ((right & 2) == 2); + } + + // 회전시키기 + private static Integer clockwise(Integer target) { + int adjust = ((target & 1) == 1) ? 128 : 0; + return (target >> 1) + adjust; + } + + private static Integer antiClockwise(Integer target) { + int adjust = ((target & 128) == 128) ? -255 : 0; + return (target << 1) + adjust; + } +} +```