From 5b1c352e921a259f53c35b367d8733e772079d70 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 21 Feb 2025 17:26:50 +0900 Subject: [PATCH] =?UTF-8?q?[20250221]=20BOJ=20/=20P3=20/=20=EC=A0=84?= =?UTF-8?q?=EC=9F=81=20=EC=A4=91=EC=9D=98=20=EC=82=B6=20/=20=EA=B6=8C?= =?UTF-8?q?=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \354\244\221\354\235\230 \354\202\266.md" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "khj20006/202502/21 BOJ P3 \354\240\204\354\237\201 \354\244\221\354\235\230 \354\202\266.md" diff --git "a/khj20006/202502/21 BOJ P3 \354\240\204\354\237\201 \354\244\221\354\235\230 \354\202\266.md" "b/khj20006/202502/21 BOJ P3 \354\240\204\354\237\201 \354\244\221\354\235\230 \354\202\266.md" new file mode 100644 index 00000000..b2eaf5fd --- /dev/null +++ "b/khj20006/202502/21 BOJ P3 \354\240\204\354\237\201 \354\244\221\354\235\230 \354\202\266.md" @@ -0,0 +1,105 @@ +```java + +import java.util.*; +import java.io.*; + +class Node{ + int cnt; + Node l, r; + Node(){ cnt = 0; } +} + +class Trie{ + Node root; + Trie(){ root = new Node(); } + + void insert(long x) { + + Stack S = new Stack<>(); + while(x > 0) { + if((x&1) == 0) S.add(0); + else S.add(1); + x >>= 1; + } + + Node now = root; + while(!S.isEmpty()) { + int a = S.pop(); + if(a == 0) { + if(now.l == null) now.l = new Node(); + now = now.l; + now.cnt++; + } + else { + if(now.r == null) now.r = new Node(); + now = now.r; + now.cnt++; + } + } + } + + int DFS(int v) { + Node now = root; + int ans = 1; + if(now.l != null) ans += dfs(now.l, v); + if(now.r != null) ans += dfs(now.r, v); + return ans; + } + + int dfs(Node now, int v) { + int res = now.cnt == v ? 0 : 1; + if(now.l != null) res += dfs(now.l, v); + if(now.r != null) res += dfs(now.r, v); + return res; + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static Trie trie; + static int N; + + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + trie = new Trie(); + + N = Integer.parseInt(br.readLine()); + nextLine(); + for(int i=0;i