From 8264d822483c0324775a24c619cdff9a96073563 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sun, 25 Jan 2026 17:45:13 +0900 Subject: [PATCH] =?UTF-8?q?[20260125]=20BOJ=20/=20G4=20/=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EC=84=9E=EA=B8=B0=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\223\234 \354\204\236\352\270\260.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "JHLEE325/202601/25 BOJ G4 \354\271\264\353\223\234 \354\204\236\352\270\260.md" diff --git "a/JHLEE325/202601/25 BOJ G4 \354\271\264\353\223\234 \354\204\236\352\270\260.md" "b/JHLEE325/202601/25 BOJ G4 \354\271\264\353\223\234 \354\204\236\352\270\260.md" new file mode 100644 index 00000000..e5477a10 --- /dev/null +++ "b/JHLEE325/202601/25 BOJ G4 \354\271\264\353\223\234 \354\204\236\352\270\260.md" @@ -0,0 +1,55 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int N = Integer.parseInt(br.readLine()); + + int[] P = new int[N]; + int[] S = new int[N]; + int[] cards = new int[N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) P[i] = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) S[i] = Integer.parseInt(st.nextToken()); + + for (int i = 0; i < N; i++) cards[i] = i; + + int[] initial = cards.clone(); + int count = 0; + + while (true) { + if (isTarget(cards, P)) { + System.out.println(count); + break; + } + + int[] nextCards = new int[N]; + for (int i = 0; i < N; i++) { + nextCards[S[i]] = cards[i]; + } + cards = nextCards; + count++; + + if (Arrays.equals(cards, initial)) { + System.out.println("-1"); + break; + } + } + } + + private static boolean isTarget(int[] cards, int[] P) { + for (int i = 0; i < cards.length; i++) { + if (P[cards[i]] != i % 3) { + return false; + } + } + return true; + } +} +```