From 5dc5c6c751b0131b376bac85fe7c0a83c59f5bd5 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Tue, 4 Feb 2025 13:13:31 +0900 Subject: [PATCH] =?UTF-8?q?[20250204]=20BOJ=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=20=EC=A3=BC=EC=82=AC=EC=9C=84=20=EC=8C=93=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\234\204 \354\214\223\352\270\260.md" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "Seol-JY/202502/04 BOJ G5 \354\243\274\354\202\254\354\234\204 \354\214\223\352\270\260.md" diff --git "a/Seol-JY/202502/04 BOJ G5 \354\243\274\354\202\254\354\234\204 \354\214\223\352\270\260.md" "b/Seol-JY/202502/04 BOJ G5 \354\243\274\354\202\254\354\234\204 \354\214\223\352\270\260.md" new file mode 100644 index 00000000..ee6b634e --- /dev/null +++ "b/Seol-JY/202502/04 BOJ G5 \354\243\274\354\202\254\354\234\204 \354\214\223\352\270\260.md" @@ -0,0 +1,79 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + private static int SIZE; + private static final int[] crossIndexes = {5, 3 ,4 ,1, 2, 0}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + SIZE = Integer.parseInt(br.readLine()); + Dice[] dices = new Dice[SIZE]; + + int answer = 0; + + StringTokenizer st; + for (int i = 0; i < SIZE; i++) { + st = new StringTokenizer(br.readLine()); + dices[i] = new Dice(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()) ,Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); + } + + for (int i = 0; i < 6; i++) { + int partialMax = dices[0].getSideMaxByIndex(i); + int nextTopValue = dices[0].getTopValueByIndex(i); + for (int j = 1; j < SIZE; j++) { + partialMax += dices[j].getSideMaxByValue(nextTopValue); + nextTopValue = dices[j].getTopValueByVlaue(nextTopValue); + } + + answer = Math.max(partialMax, answer); + } + + System.out.println(answer); + } + + + public static class Dice { + int[] numbers; + public Dice(int ...numbers) { + this.numbers = numbers; + } + + public int getSideMaxByValue(int bottomValue) { + int max = 0; + int topValue = getTopValueByVlaue(bottomValue); + for (int i = 0; i < 6; i++) { + if (numbers[i] == bottomValue || numbers[i] == topValue) continue; + max = Math.max(max, numbers[i ]); + } + return max; + } + + public int getSideMaxByIndex(int bottomIndex) { + int max = 0; + int topValue = getTopValueByVlaue(numbers[bottomIndex]); + for (int i = 0; i < 6; i++) { + if (numbers[i] == numbers[bottomIndex] || numbers[i] == topValue) continue; + max = Math.max(max, numbers[i]); + } + return max; + } + + public int getTopValueByVlaue(int bottomValue) { + for (int i = 0; i < 6; i++) { + if (numbers[i] == bottomValue) { + return getTopValueByIndex(i); + } + } + + return -1; + } + + public int getTopValueByIndex(int bottomIndex) { + return numbers[crossIndexes[bottomIndex]]; + } + } +} + +```