optimize for dumb pr
This commit is contained in:
parent
d32acd64fd
commit
90de771f84
@ -26,14 +26,14 @@ char get_max_char(std::string_view s) {
|
||||
}
|
||||
|
||||
int64_t solve(const std::string_view line, size_t cnt_to_activate) {
|
||||
const auto search{line.substr(0, line.size() - cnt_to_activate + 1)};
|
||||
const std::string_view search{line.substr(0, line.size() - cnt_to_activate + 1)};
|
||||
const char max_char{get_max_char(search)}, null_terminator{'\0'};
|
||||
const auto max_char_idx{search.find(&max_char, 0)};
|
||||
const size_t max_char_idx{search.find(&max_char, 0)};
|
||||
const int64_t max_char_as_int = max_char - '0';
|
||||
if (cnt_to_activate == 1) {
|
||||
return max_char_as_int;
|
||||
}
|
||||
const auto recur{solve(line.substr(max_char_idx + 1), cnt_to_activate - 1)};
|
||||
const int64_t recur{solve(line.substr(max_char_idx + 1), cnt_to_activate - 1)};
|
||||
// slightly hacky... integral concat better?
|
||||
return std::stoll(std::string(&max_char) + std::to_string(recur));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user