Computers and Technology

Consider a prison gate having N horizontal rods and M vertical rods. You are also provided with two vectors hor and ver containing the
row number of missing horizontal rods and vertical rods respectively.
Return the area of biggest hole in the prison gate.
1 <= N, M <= 1000000
1 <= hor[i] <= N
1 <= ver[i] <= M
All the elements of a vector are distinct
O(N + M)
SKIPPING... O(AlogA + BlogB) where A = hor. size() and B = ver. size()
*/
#include
using namespace std;
long int prison(int n, int m, vector hor, vector ver) {
vector xs(n + 1), ys(m + 1);
for (int h : hor) xs[h] = true;
for (int v : ver) ys[v] = true;
int xm = 0, ym = 0;
for (int i = 1, j = 0; i <= n; i++) { if (not xs[i]) j = 0;
else xm = max(xm, ++j);
}
for (int i = 1, j = 0; i <= m; i++) {
if (not ys[i]) j = 0;
else ym = max(ym, ++j);
}
return (long int)(xm + 1) * (ym + 1);
}
int main() {
cout << prison(10, 10, {}, {});
return 0;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 11:00, swelch2010
Describe three characteristics of at-risk drivers. a. b. c. describe three characteristics of safe drivers. a. b. c. describe three driver errors that could cause a collision. a. b. c. how will this information affect you as a driver now and in the future? (2-3 sentences)
Answers: 2
image
Computers and Technology, 23.06.2019 15:20, headshotplayzcod
In a game with three frames, where will the objects on layer 1 appear? a. next to the play area b. in the middle of the game c. behind everything else d. in front of everything else
Answers: 1
image
Computers and Technology, 24.06.2019 02:00, akatherine1738
What is a loop? a. a collection of function definitions at the top of a program b. a line of code that defines a variable and assigns it a value c. a program that opens the turtle graphics window d. a block of code that repeats a specific number of times
Answers: 1
image
Computers and Technology, 25.06.2019 04:50, mlinares776
Your program should prompt the user for the dimensions of the two squares matrices, making sure that the user input is greater than or equal to 4.[ yes, an example would be a4x4matrix]2.if the above is not met, prompt the user for a new value.3.now generate random integernumbers to fill both matrices.4.display these two matrices on the screen.5.multiply the two matrices and display the result on the scre
Answers: 2
Do you know the correct answer?
Consider a prison gate having N horizontal rods and M vertical rods. You are also provided with two...

Questions in other subjects:

Konu
Mathematics, 27.03.2021 01:00
Konu
Mathematics, 27.03.2021 01:00
Konu
Mathematics, 27.03.2021 01:00