TheMoviesLevelOneDivOne
SRM 469 · 2009-11-12 · by Vasyl[alphacom]
SRM 469 · 2009-11-12 · by Vasyl[alphacom] · Simple Math
Problem Statement
Problem Statement
John and Brus are going to a theater to see a very interesting movie. They would like to have seats next to each other in the same row. The theater contains n rows, with m seats in each row. Rows are numbered 1 to n from front to back, and seats are numbered 1 to m from left to right. Some of the seats are already reserved, but John and Brus can book any of the available seats.
You are givenint[] s row and seat. The i-th elements of row and seat are the row number and seat number of the i-th reserved seat. All remaining seats are available. Return the number of ways for John and Brus to book two available seats next to each other in the same row.
You are given
Notes
- Two bookings are considered different only if one contains a seat that the other does not contain. In other words, they don't need to decide which seat John sits in and which seat Brus sits in.
Constraints
- n and m will each be between 1 and 1,000,000,000, inclusive.
- row will contain between 1 and 47 elements, inclusive.
- row and seat will contain the same number of elements.
- Each element of row will be between 1 and n, inclusive.
- Each element of seat will be between 1 and m, inclusive.
- All pairs (row[i], seat[i]) will be distinct.
Examples
0)
2
3
{1, 2}
{2, 3}
Returns: 1
The first and the second seat in the second row are the only two free seats next to each other in the same row.
1)
2
3
{1, 1, 1, 2, 2, 2}
{1, 2, 3, 1, 2, 3}
Returns: 0
There are no free seats in the theater.
2)
4
7
{1}
{1}
Returns: 23
3)
10
8
{1, 9, 6, 10, 6, 7, 9, 3, 9, 2}
{7, 7, 3, 3, 7, 1, 5, 1, 6, 2}
Returns: 54
4)
7
9
{5, 4, 6, 5, 4, 3, 6}
{9, 3, 4, 4, 4, 9, 3}
Returns: 46
Submissions are judged against all 119 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class TheMoviesLevelOneDivOne with a public method long long find(int n, int m, vector<int> row, vector<int> seat) · 119 test cases · 2 s / 256 MB per case