From a2861d9f5d4e1939f05bd3d90fb862f0fa54116a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EC=9D=B4=EB=AC=B8=EB=B9=88?= <3412mb@gmail.com>
Date: Fri, 8 Mar 2024 06:45:33 +0900
Subject: [PATCH] =?UTF-8?q?2024-03-08=20=EC=A0=84=ED=99=94=EB=B2=88?=
=?UTF-8?q?=ED=98=B8=20=EB=AA=A9=EB=A1=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Munbin-Lee/README.md | 1 +
...\355\230\270 \353\252\251\353\241\235.cpp" | 80 +++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 "Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp"
diff --git a/Munbin-Lee/README.md b/Munbin-Lee/README.md
index 13e29ef2..1be0e769 100644
--- a/Munbin-Lee/README.md
+++ b/Munbin-Lee/README.md
@@ -38,4 +38,5 @@
| 35차시 | 2024.02.18 | 백트래킹 | 단어 마방진 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/140 |
| 36차시 | 2024.02.21 | 문자열 | 회문은 회문아니야!! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143 |
| 37차시 | 2024.03.05 | 백트래킹 | 석유 시추 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/150 |
+| 37차시 | 2024.03.08 | 트라이 | 전화번호 목록 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
---
diff --git "a/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp" "b/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp"
new file mode 100644
index 00000000..5e5033f9
--- /dev/null
+++ "b/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp"
@@ -0,0 +1,80 @@
+#include
+#include
+
+using namespace std;
+
+struct Trie {
+ struct Node {
+ Node *children[10]{};
+ bool isTerminal = false;
+ };
+
+ Node *root = new Node;
+
+ bool insert(string &s) const {
+ auto cur = root;
+
+ for (char ch: s) {
+ int digit = ch - '0';
+
+ if (!cur->children[digit]) {
+ cur->children[digit] = new Node();
+ cur = cur->children[digit];
+ continue;
+ }
+
+ if (cur->children[digit]->isTerminal) {
+ return false;
+ }
+
+ cur = cur->children[digit];
+ }
+
+ for (auto child: cur->children) {
+ if (child) {
+ return false;
+ }
+ }
+
+ cur->isTerminal = true;
+
+ return true;
+ }
+};
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(nullptr);
+
+ auto solve = []() {
+ auto trie = new Trie;
+
+ int n;
+ cin >> n;
+
+ vector numbers(n);
+
+ for (auto &number: numbers) {
+ cin >> number;
+ }
+
+ for (auto number: numbers) {
+ if (!trie->insert(number)) {
+ cout << "NO\n";
+ delete trie;
+ return;
+ }
+ }
+
+ cout << "YES\n";
+ };
+
+ int t;
+ cin >> t;
+
+ while (t--) {
+ solve();
+ }
+
+ return 0;
+}