#C10908. Badge Log Discrepancy Detector
Badge Log Discrepancy Detector
Badge Log Discrepancy Detector
You are given a series of badge log records that track staff entries and exits. For each test case, the first line contains an integer N representing the number of log entries. Each of the following N lines contains three tokens: an integer employee ID, a string representing the action (either entry
or exit
), and a timestamp (in HH:MM format). The first line of input contains an integer T representing the number of test cases.
Your task is to analyze the logs for each test case and determine whether there is any discrepancy in the badge system. A discrepancy exists if an employee attempts to enter when they are already inside, or exit when they are not inside. For each test case, output "YES" if the logs are consistent, or "NO" if any discrepancy is found.
Note: Any action other than entry
or exit
should be treated as an anomaly which might eventually lead to a discrepancy.
The relation can be formally stated as:
For each log record, let s be the current status of an employee. Then:
[ \text{if action} = \texttt{entry}:\quad s_{new} = \begin{cases} \texttt{entry} & \text{if } s \neq \texttt{entry} \ \text{discrepancy} & \text{if } s = \texttt{entry} \end{cases} ]
[ \text{if action} = \texttt{exit}:\quad s_{new} = \begin{cases} \texttt{exit} & \text{if } s = \texttt{entry} \ \text{discrepancy} & \text{if } s \neq \texttt{entry} \end{cases} ]
inputFormat
The input is read from stdin and has the following format:
T N employee_id action timestamp employee_id action timestamp ... (N lines for test case 1) N employee_id action timestamp ... (N lines for test case 2) ...
Where T is the number of test cases, and for each test case, N is the number of badge log records.
outputFormat
For each test case, print a single line containing either YES
if the badge log records are consistent, or NO
if a discrepancy is detected. The output is printed to stdout.
3
4
1 entry 09:00
2 entry 09:10
1 exit 17:00
2 entry 16:00
5
3 entry 08:00
3 exit 12:00
3 entry 13:00
3 exit 17:00
4 entry 09:45
3
4 entry 09:00
4 entry 12:00
4 exit 18:00
NO
YES
NO
</p>