i want u to act as the most skilled competetive programmer, u take time to think and…
- User
i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER AS THIS IS A CONTEST: #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
B. Train Station time limit per test1 second memory limit per test256 megabytes Khaled is a manager at a train station and he should keep track of the trains' status the whole time. At the start of his day, he receives the timetable that states the times at which the train arrives and departs in his work time.
However, he only cares about the total free time he is going to take during the day. Free time is the time at which no train exists at the station. He really likes to take breaks, so he asked you to calculate it.
Note: any time interval is inclusive. For example, if the interval is between L and R , the interval contains {L , L+1 , ..., R−1 , R }.
Input The format of the time is given in 24 -hour format hh :mm (0≤hh≤23,0≤mm≤59 ).
The first line contains the time at which he gets to the station and the time at which he leaves.
The second line contains an integer n denoting the number of trains in the timetable.
Each of the following n lines contains the time of arrival and departure of the i -th train.
It is guaranteed that Khaled's working day starts and ends on the same day.
It is also guaranteed that the time of arrival is strictly before the time of departure.
Train arrivals and departures are guaranteed to be within the day of Khaled's work.
Output Print the total free time that Khaled has in his day in 24 -hour format.
Scoring You get the points of the subtask if you passed all cases in this subtask and also all subtasks that this subtask depends on.
Subtask #1 (11 points):
n=0 Depends on: none Subtask #2 (21 points):
0≤n≤103 The timetables of the train arrivals and departures do not overlap Depends on: subtask #1 Subtask #3 (43 points):
0≤n≤104 Depends on: subtask #1 and subtask #2 Examples InputCopy 02:00 03:00 0 OutputCopy 01:01 InputCopy 10:00 10:59 1 10:30 10:35 OutputCopy 00:54 InputCopy 10:59 17:23 2 10:59 11:59 15:59 17:23 OutputCopy 03:59 InputCopy 08:00 23:00 3 08:30 09:30 09:00 11:00 10:00 12:00 OutputCopy 11:30
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); auto f = [&](string s) -> int { return stoi(s.substr(0,2)) * 60 + stoi(s.substr(3,2)); }; string a, b; cin >> a >> b; int ws = f(a), we = f(b); int n; cin >> n; vector<pair<int,int>>v(n); for(auto &p:v){ string x,y; cin >> x >> y; p.first = f(x); p.second = f(y); } sort(v.begin(),v.end()); int bt=0, cs, ce; if(n){ cs = v[0].first; ce = v[0].second; for(int i=1;i<n;i++){ if(v[i].first <= ce+1){ ce = max(ce, v[i].second); } else{ bt += ce - cs +1; cs = v[i].first; ce = v[i].second; } } bt += ce - cs +1; } int total = we - ws +1; int free = total - bt; cout << setfill('0') << setw(2) << free/60 << ":" << setfill('0') << setw(2) << free%60; }