Attendance

3.3

7 votes
, Linear Search, Algorithms, C++, Real world
Problem

As per COVID-19 rules, your college is taking online classes. Your professor takes class from StartTime(hh:mm:ss) to EndTime(hh:mm:ss). He uses a chrome extension to track when a student joins the class and leaves the class with their Student ID(SID). He stores it in a student tracker file and then circulates it in your college group.  Now, your teacher is very strict. He wants to take attendance at a moment when the number of students present in the class is minimum. If there are multiple such times he can choose a time with equal probability and will take the attendance. Now, you know your teacher's algorithm and you have access to the student tracker file.

Task

Print 0 if the probability that you (SID=1) will get the attendance is zero otherwise print the probability in P/Q format where GCD(P, Q)=1, where GCD(P, Q) denotes the greatest common divisor of integers P and Q.

Note: Each student can join the class at multiple intervals. Like they can join at "12:00:00" then leave at "12:15:00", then again join at "12:35:00", and leave at "12:50:00".

Example

Assumptions

  • N = 2
  • StartTime = "12:00:00"
  • EndTime = "12:45:00"
  • The next N lines are:
    • SID1 = 2, M1 = 2, Time1 = [[12:00:00, 12:15:00] [12:20:00, 12:45:00]]
    • SID2 = 1, M2 = 1, Time2 = [[12:00:00, 12:44:00]]

Approach

  • The minimum number of students is 1 and is at any second from "12:15:00" to "12:19:59" or at any second from "12:44:00" to "12:44:59".
  • During these times you are available from "12:15:00" to "12:19:59".
  • So the probability that you(SID=1) will get the attendance is 5/6.

Input format

Note: This is the input format you must use to provide custom input (available above the Compile and Test button).

  • The first line contains denoting the number of students.
  • The second line contains two space-separated strings StartTime and EndTime of class in hh:mm: ss format("00:00:00" to "23:59:59")
  • The next N lines have Student ID(SID), the number of intervals the student joined the class(M), and M pairs of [ArrivalTime, LeaveTime] in hh:mm:ss format for each M interval.

Output format

Print 0 if the probability that you (SID=1) will get the attendance is zero otherwise print the probability in P/Q format where GCD(P, Q)=1, where GCD(P, Q) denotes the greatest common divisor of integers P and Q.

Constraints

\(\ 2 \leq N \leq 10^3 \\00:00:00\leq StartTime<EndTime\leq 23:59:59 \\1\leq SID_i\leq 10^3\\1\leq M_i\leq5\)

Sample Input
3
12:00:00 13:00:00
2 2 12:00:00 12:25:00 12:56:00 13:00:00
1 1 12:00:00 12:56:00
3 1 12:00:00 13:00:00
Sample Output
31/35
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Example

Given

  • N = 3
  • StartTime = "12:00:00"
  • EndTime = "13:00:00"
  • Next N lines are:
    • SID1 = 2, M1 = 2, Time1 = [[12:00:00, 12:25:00] [12:56:00, 13:00:00]]
    • SID2 = 1, M2 = 1, Time2 = [[12:00:00, 12:56:00]]
    • SID2 = 3, M2 = 1, Time2 = [[12:00:00, 13:00:00]]

Approach

  • The minimum number of students is 2 and is at any second from "12:25:00" to "12:59:59".
  • During these times you are available from "12:25:00" to "12:55:59".
  • So the probability that you(SID=1) will get the attendance is 31/35.
Editor Image

?