From a2cd22570adc65b626d75cbbb9d97330eb34211c Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Wed, 6 Aug 2025 19:25:08 -0600 Subject: [PATCH 1/2] trie golf --- library/strings/trie.hpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/library/strings/trie.hpp b/library/strings/trie.hpp index f8ce264a..3cf12e3a 100644 --- a/library/strings/trie.hpp +++ b/library/strings/trie.hpp @@ -1,17 +1,13 @@ #pragma once //! https://cp-algorithms.com/string/aho_corasick.html#construction-of-the-trie -const int mn = 'A', - cnt_let = 26; // mn <= s[i] < mn + cnt_let +const int mn = 'A'; struct trie { struct node { - array next; - int cnt_words = 0, par = -1; - char ch; - node(int par = -1, char ch = '#'): par(par), ch(ch) { - fill(all(next), -1); - } + array next; + bool end_of_word = 0; + node() { fill(all(next), -1); } }; - vector t; + deque t; trie(): t(1) {} void insert(const string& s) { int v = 0; @@ -19,11 +15,11 @@ struct trie { int u = ch - mn; if (t[v].next[u] == -1) { t[v].next[u] = sz(t); - t.emplace_back(v, ch); + t.emplace_back(); } v = t[v].next[u]; } - t[v].cnt_words++; + t[v].end_of_word = 1; } int find(const string& s) { int v = 0; @@ -32,6 +28,6 @@ struct trie { if (t[v].next[u] == -1) return 0; v = t[v].next[u]; } - return t[v].cnt_words; + return t[v].end_of_word; } }; From f61f162cfbf381ff1701080163169a25cd50b40d Mon Sep 17 00:00:00 2001 From: GitHub Date: Thu, 7 Aug 2025 01:26:17 +0000 Subject: [PATCH 2/2] [auto-verifier] verify commit a2cd22570adc65b626d75cbbb9d97330eb34211c --- .verify-helper/timestamps.remote.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index b5621895..525611a3 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -124,7 +124,7 @@ "tests/library_checker_aizu_tests/strings/single_matching_bs.test.cpp": "2025-08-05 19:19:23 -0600", "tests/library_checker_aizu_tests/strings/suffix_array.test.cpp": "2025-08-06 09:59:41 -0600", "tests/library_checker_aizu_tests/strings/suffix_array_short.test.cpp": "2025-08-05 19:19:23 -0600", -"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2024-12-05 10:41:42 -0600", +"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2025-08-06 19:25:08 -0600", "tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2025-08-05 19:19:23 -0600", "tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2025-08-06 13:48:07 -0600", "tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2025-08-06 19:02:15 -0600",