题目描述
Problem Description
Andou-kun executed $ N $ scripts and recorded their start and end times.
However, on this day, Andou-kun's clock experienced a time warp event where it went back by $ 1000 $ milliseconds once.
This might have caused uncertainty in the execution times of the scripts.
Given the list of start and end times for each script, calculate and output the execution time for each script in milliseconds.
Please note the following:
- Output
-1for scripts whose execution time cannot be uniquely determined. - All script execution times were at least $ 1 $ millisecond.
- The time warp was an instantaneous event, and the time taken for the warp was $ 0 $ milliseconds.
- There was no rounding in the recorded start and end times, and all sub-millisecond values were $ 0 $.
That is, for the millisecond value $ t $ of the start and end times, $ t $ is known to be an integer. - The sub-millisecond value of the time warp occurrence was not $ 0 $.
That is, for the millisecond value $ r $ of the time warp occurrence, $ r $ is known to be non-integer.
Therefore, the time warp did not occur at the same time as the start or end times. - There is no daylight saving time.
Input Format
The input is given from the standard input in the following format:
$ N $ $ S_1 $ $ E_1 $ : $ S_N $ $ E_N $
- The number of scripts $ N $ ( $1 \leq N \leq 100$ ) is given in one line.
- The following $ N $ lines contain the start time $ S_i $ and end time $ E_i $ for each script, separated by a space.
- The format of $ S_i $ and $ E_i $ is
HH:MM:SS.mmm, whereH,M,S,mrepresent single digits.
Also,21$\leq$HH$\leq$22,00$\leq$MM$\leq$59,00$\leq$SS$\leq$59,000$\leq$mmm$\leq$999. - Inputs that do not satisfy the problem conditions, such as multiple time warps, will not be given.
Output Format
Output the execution time of each script in milliseconds, one per line.
For scripts whose execution time cannot be uniquely determined, output -1.
Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
1
21:00:01.500 21:00:01.000
Sample Output #1
500
Sample Input #2
1
22:00:00.000 22:00:03.000
Sample Output #2
-1
Sample Input #3
3
21:00:00.000 21:00:03.000
21:00:01.500 21:00:01.000
21:00:02.000 21:00:02.500
Sample Output #3
4000
500
500
Sample Input #4
3
21:00:00.000 21:00:03.000
21:00:01.500 21:00:01.000
21:00:00.500 21:00:01.000
Sample Output #4
4000
500
-1
Notes/Hints
Scoring
This problem does not have partial points. If you correctly solve all test cases, you will be awarded $ 50 $ points.
Sample Explanation 1
Since the end time of the script is before its start time, it is clear that a time warp occurred during execution.
Sample Explanation 2
It is not possible to determine if a time warp occurred during the script's execution. It could be either $ 4000 $ milliseconds if a warp occurred or $ 3000 $ milliseconds if it did not.
Sample Explanation 3
From the second script, it is clear that the time warp occurred after 21:00:01.500 and before 21:00:02.000 on the pre-warp timeline.
Sample Explanation 4
Similar to Sample Input #3, from the second script, it is clear that the time warp occurred after 21:00:01.500 and before 21:00:02.000 on the pre-warp timeline. However, it is not possible to determine if the end time of the third script is recorded on the pre-warp timeline or the post-warp timeline.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分