Connection Status:
Competition Arena > OpenAllHours
SRM 792 · 2020-10-21 · by misof · Brute Force, Simple Math, Simulation
Class Name: OpenAllHours
Return Type: String
Method Name: verify
Arg Types: (int, vector<string>, vector<string>)
Problem Statement

Problem Statement

In this problem we are using a 24-hour clock. The clock shows time in hours and minutes, from 00:00 (midnight) to 23:59 (one minute before the next midnight). These times are given as Strings. Each time always has the form "HH:MM", using leading zeros if needed.

The ACME company claims they are open all hours. You would like to verify whether their claim is true.

The company has N branches all over the town. The branches are numbered from 0 to N-1. Each branch has its own opening and closing hours. More precisely, each day branch i opens in the moment when a 24-hour clock starts showing the time openingTime[i], and closes in the moment when the clock starts showing the time closingTime[i]. (It is guaranteed that for each branch its opening time is different from its closing time.)

If the ACME company indeed has at least one branch open during every minute of the day, return "correct". Otherwise, return "incorrect". (Quotes for clarity only. Note that the return value is case-sensitive.)

Constraints

  • N will be between 1 and 50, inclusive.
  • openingTime and closingTime will each have exactly N elements.
  • Each element of openingTime and closingTime will have the form "HH:MM", with 00 <= HH <= 23 and 00 <= MM <= 59.
  • For each valid index i, openingTime[i] and closingTime[i] will differ.
Examples
0)
2
{"04:47","16:47"}
{"16:47","04:47"}
Returns: "correct"

This company has two branches. Each of them is open exactly 12 hours: one from 4:47am to 4:47pm and the other from 4:47pm through midnight all the way to 4:47am on the next day. In the same moment in which one of them closes the other one opens, and so exactly one branch is open during each part of the day.

1)
3
{"03:00", "18:30", "08:59"}
{"09:00", "04:15", "19:01"}
Returns: "correct"

Three branches with partially overlapping opening hours. Sometimes two of them are open at the same time, but always at least one of them is open.

2)
3
{"03:47", "03:48", "03:49"}
{"03:44", "03:45", "03:46"}
Returns: "incorrect"

Each of these three branches only closes for three minutes, but their closing times overlap. During the minute between the exact moments 03:46 and 03:47 all three branches are closed.

3)
1
{"05:00"}
{"04:59"}
Returns: "incorrect"

There is only one branch and it is closed for a single minute each day. (Note that inputs in which a branch has the same opening and closing time are not allowed by the constraints, so no branch can be opened for longer than this one.)

4)
2
{"02:08", "18:53"}
{"16:50", "10:23"}
Returns: "incorrect"

Submissions are judged against all 60 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OpenAllHours with a public method string verify(int N, vector<string> openingTime, vector<string> closingTime) · 60 test cases · 2 s / 256 MB per case

Submitting as anonymous