You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solutions/gold/cf-100886G.mdx
+6-7
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ If $l = 1$, what will the best solution always be?
10
10
</Spoiler>
11
11
## Explanation
12
12
### $l = 1$
13
-
Let's start with an example: $l = 1$ and $r = 875$. Observe that we really need to consider three numbers as viable answers: $875$, $799$, and $869$. Try to think about why, and how this generalizes!
13
+
Let's start with an example: $l = 1$ and $r = 875$. Observe that we really need to consider three numbers as viable answers: $875$, $799$, and $869$. Try to think about why, and how this generalizes!
14
14
### $l \neq 1$
15
15
We can apply a very similar approach when $l \neq 1$. In fact, it's almost identical, with one minor difference. Consider the case where $l = 855$ and $r = 875$, just as before. The only difference is we can no longer consider $799$ as a viable answer, as it is less than $l$. Again, try to think about how to generalize this!
16
16
@@ -43,15 +43,15 @@ int main() {
43
43
while (l.length() < r.length()) { l.insert(l.begin(), '0'); }
44
44
string ans = "";
45
45
// i -> length of LCP (longest common prefix) of str and r
46
-
bool eq = true; // whether l[0, i) = r[0, i)
46
+
bool eq = true; // whether l[0, i) = r[0, i)
47
47
for (int i = 0; i <= r.length(); i++) {
48
48
string cur = r.substr(0, i);
49
49
eq = eq && l[i] == r[i];
50
50
/*
51
-
* in this case, str[i] must equal r[i]
52
-
* and now the shared prefix has length i + 1
53
-
* which contradicts our assumption that the LCP has length i
54
-
*/
51
+
* in this case, str[i] must equal r[i]
52
+
* and now the shared prefix has length i + 1
53
+
* which contradicts our assumption that the LCP has length i
0 commit comments