Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
![]() | Accepted | C++11 | 0.000 | 0.000 | 1972 | 5 mins ago |
Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
![]() | Accepted | C++11 | 0.000 | 0.000 | 1972 | 5 mins ago |
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
![]() | Accepted | C++11 | 0.000 | 0.000 | 183 | 1 mins ago |
Suggest:
- Almost prime is the exponential of a prime number
- To find all the multipliers of prime numbers in the given time, we use the sieve prime
- After getting all the almost primes, to find out how many numbers are in a segment we use sort + binary search
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
![]() | Accepted | C++11 | 0.000 | 0.000 | 1359 | 3 mins ago |
![]() | Wrong answer | C++11 | - | 0.000 | - | 26 mins ago |
![]() | Wrong answer | C++11 | - | 0.000 | - | 45 mins ago |
![]() | Wrong answer | C++11 | - | 0.000 | - | 54 mins ago |
![]() | Wrong answer | C++11 | - | 0.000 | - | 1 hours ago |
![]() | Wrong answer | C++11 | - | 0.000 | - | 1 hours ago |
Suggest:
- max_page is mid of binary_search
- Binary search to find max_page of scribers, when you have max_page you should greedy from right to left (book n -> 1) to get /
- Greedy right to left because they said: "If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book."
}
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
![]() | Accepted | C++11 | 0.050 | 0.000 | 1352 | 3 mins ago |
Suggest:
If you are stuck on this problem, it means you are not familiar with binary techniques. Please refer to my implementation in the code snippet below. This implementation requires an additional for loop to obtain the final result, but its advantage is that you don't need to modify the mid calculation (in some cases, if you don't change this calculation, you will loop infinitely).
Binary search is an efficient search algorithm used on a sorted array. Its strength lies in quickly identifying the desired value by dividing the array into smaller segments and eliminating the half of the array that does not contain the target value.
In the given source code, binary search is used to find an approximate value within the range from l to r. The goal is to find a value m for which the function f(m) returns true.
The function f(k) checks whether the value k satisfies a specific condition. In this case, we want to find a value k such that:
If a[i-1] + k < a[i], then k is invalid and the function returns false.
If a[i-1] + k == a[i], then k is decremented by 1 and the check continues with the next element.
In the main loop, the variable l is initialized as 1 and r as 1e7 (10^7). Binary search is employed to find the value m that satisfies f(m). The loop continues to halve the search range until the remaining range has only 3 elements (r-l+1>3).
In each binary search step, the average value m of l and r is computed, and it is checked whether f(m) returns true. If f(m) returns true, r is assigned as m to narrow down the search range to the first half. If f(m) returns false, l is assigned as m to narrow down the search range to the second half.
Finally, after finding a remaining range of length 3 (r-l+1=3), each value within that range is checked to determine the exact value. We search for value i within the range from l to r for which f(i) returns true. Once that value is found, we print the result.