From ed874c6aaf931aa0f1e3f1634a3a4c4a3f436612 Mon Sep 17 00:00:00 2001 From: sukangpunch Date: Fri, 16 Jan 2026 15:09:37 +0900 Subject: [PATCH] =?UTF-8?q?[Week02]=20PGS=2012936:=20=EC=A4=84=20=EC=84=9C?= =?UTF-8?q?=EB=8A=94=20=EB=B0=A9=EB=B2=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sukangpunch.java" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "weekly/week02/PGS_\354\244\204\354\204\234\353\212\224\353\260\251\353\262\225/sukangpunch.java" diff --git "a/weekly/week02/PGS_\354\244\204\354\204\234\353\212\224\353\260\251\353\262\225/sukangpunch.java" "b/weekly/week02/PGS_\354\244\204\354\204\234\353\212\224\353\260\251\353\262\225/sukangpunch.java" new file mode 100644 index 0000000..a6428c5 --- /dev/null +++ "b/weekly/week02/PGS_\354\244\204\354\204\234\353\212\224\353\260\251\353\262\225/sukangpunch.java" @@ -0,0 +1,55 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +// 줄 서는 방법 +// 정답 확인 +public class PGS_12936 { + + static List list; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + long K = Integer.parseInt(br.readLine()); + + list = new ArrayList<>(); + for (int i = 0; i < N; i++) { + list.add(i + 1); + } + + int[] result = solution(N, K); // 인덱스 접근을 위해 k-1 + System.out.println(Arrays.toString(result)); + } + + public static int[] solution(int N, long K) { + int[] answer = new int[N]; + + int idx = 0; + int n = N; + long k = K-1; + + while (idx < N) { + long fact = fact(n - 1); + long range = k / fact; + answer[idx] = list.remove((int) range); + n -= 1; + k -= fact * range; + idx++; + } + + return answer; + } + + private static long fact(int n) { + long result = 1; + for (int i = 2; i <= n; i++) { + result *= i; + } + return result; + } +}