File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1+ #include " common.h"
2+
3+ namespace {
4+ long p (const auto &input, size_t m) {
5+ const auto &s = input[0 ];
6+ std::unordered_map<char , long > st;
7+ for (size_t i = 0 ; i < m - 1 ; ++i)
8+ st[s[i]] += 1 ;
9+
10+ for (size_t i = m - 1 ; i < s.size (); ++i) {
11+ st[s[i]] += 1 ;
12+ if (st.size () == m)
13+ return i + 1 ;
14+ st[s[i - m + 1 ]] -= 1 ;
15+ if (!st.at (s[i - m + 1 ])) {
16+ st.erase (s[i - m + 1 ]);
17+ }
18+ }
19+ return -1 ;
20+ }
21+ } // namespace
22+
23+ int main () {
24+ const auto &input = gb::advent2021::readIn ();
25+ gb::advent2021::writeOut (std::to_string (p (input, 4 )));
26+ gb::advent2021::writeOut (std::to_string (p (input, 14 )));
27+ }
Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ executable('5',
2222 ' 5.cpp' ,
2323 dependencies : [])
2424
25- # executable('6',
26- # '6.cpp',
27- # dependencies: [])
25+ executable (' 6' ,
26+ ' 6.cpp' ,
27+ dependencies : [])
2828
2929# executable('7',
3030# '7.cpp',
You can’t perform that action at this time.
0 commit comments