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; + } +} +```