## CCO '13 P4 - A Romantic Movie Outing

View as PDF

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Canadian Computing Competition: 2013 Stage 2, Day 2, Problem 1

Brian the Computer Science Nerd is going on a date with his girlfriend, Anatevka! His romantic location of choice is a movie theatre - but not an IMAX theatre, of course, as that would be far too expensive.

This theatre has rows of seats each, which are initially empty. The rows are numbered starting from the one closest to the screen, and the seats in each row are numbered from left to right. Seat in row is denoted as seat . Seats in rows are considered to be close to the screen, while seats in further rows are considered to be far.

Over the course of () minutes before the movie starts, a number of events occur. During the -th minute, either a person enters and sits in the empty seat , the person sitting in the occupied seat leaves, or Anatevka suggests that she and Brian take seats and . The type of the -th event is represented by the character , with = E indicating a person entering, = L indicating a person leaving, and S indicating a seating suggestion. All seats involved in the events are valid seats inside the theatre, and every seat that Anatevka suggests will be close, as she believes that they're the best.

Every time Anatevka makes a suggestion, Brian must, of course, analyze its quality. If either of the two seats she suggests is already occupied, he should explain to her that her recommendation is invalid with a simple No. Otherwise, he'd like to calculate the total inconvenience of both seats in such an arrangement. The inconvenience of sitting in seat is the number of occupied seats in its field of vision, excluding itself. The field of vision of seat includes all seats which are no further than it from seat by Manhattan distance (i.e., Manhattan distance between and is ). as shown below (with the S representing a suggested seat, and an F representing a seat within its field of vision:

 S F F F F F F F F F F F F F F F

After all the events have taken place, the movie is about to start, and a final decision must be made on where to sit - and Brian will handle that. He conclude that seats that are far are clearly superior (as they offer a broader view of the screen), and he knows that the point of going to the movies is to have an optimal viewing experience, so selecting two adjacent seats is cetainly not mandatory. As such, he'd like to determine the minimum total inconvenience for any two far unoccupied seats in the theatre. Note that, if one of the chosen seats is in the other's field of vision, this does not count toward its inconvenience - it's only determined by other people sitting in the theatre.

#### Input Specification

The first line of each test case contains two integers, () and ().

The next lines each contain one character, where , and two integers, and , for (; ).

For test cases worth of the points, you may assume and .

For test cases worth of the points, you may assume and .

#### Output Specification

For each of Anatevka's suggestions (i.e. when S in the input), output the string No if the suggestion is invalid; otherwise, output the total inconvenience of the two suggested seats.

The last line of output should contain the minimum total inconvenience of any pair of far, unoccupied seats.

#### Sample Input

3 7
E 1 2
E 2 5
S 3 4
E 2 3
L 2 5
S 1 3
S 2 2

#### Output for Sample Input

3
0
No
0

#### Explanation of Output for Sample Input

When Anatevka makes her first suggestion, the front rows and leftmost columns of the theatre look as follows (where a P represents a person, and an S represents one of the suggested seats)

 S S P P

The second suggestion is shown below:

 P P S S

These two seats aren't obstructed by any people, so their total inconvenience is . The final suggestion is invalid, as one of its two seats (seat ) is already occupied.

Finally, Brian can easily select two far seats which each have inconvenience , as the theatre has far rows with seats each, and most are far from the two people setting in the theatre after the last event. For example, he might choose to take seat , while recommending that Anatevka enjoy the view from seat .

• commented on Jan. 2, 2019, 7:09 p.m.

Hint

Which data structure do we need for this problem?

• commented on Jan. 29, 2018, 5:19 p.m.

Question

Could someone please explain to me how the Field of View works? How is (1,2) in the FOV of (3,5) but (2,5) is not in the FOV of (3,4) ???? The problem description of manhattan distance does not make sense to me, I have looked at what manhattan distance is but I still dont get it

• commented on Oct. 29, 2016, 12:04 p.m. edit 2

Fixed the second image which corresponds to Anatevka's first suggestion.

Also, fixed invald, as was pointed out by d in his profile.

• commented on Aug. 28, 2015, 1:46 p.m. edited

http://wcipeg.com/problem/ccc13s2p4

This theatre has 10^9 rows of 1000 seats each, which are initially empty. The rows are numbered 1..10^9 starting from the one closest to the screen, and the seats in each row are numbered 1..1000 from left to right. Seat c in row r is denoted as seat (r,c). Seats in rows 1..L (1 ≤ L ≤ 1000) are considered to be “close” to the screen, while seats in further rows are considered to be “far”.
• commented on Aug. 28, 2015, 3:06 p.m.

Fixed.

• commented on Aug. 28, 2015, 3:44 p.m.

Also I'm confused, if Anatevka first suggested 3, 4 then why is the first picture showing spots 3, 3 and 3, 4? Shouldn't it be 3, 4 and 3, 5?

• commented on Aug. 28, 2015, 4:12 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.