This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#1095 Cars on Campus.cpp
49 lines (43 loc) · 1.83 KB
/
#1095 Cars on Campus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef tuple<string, unsigned, bool> Record;
typedef pair<unsigned, bool> noPlateRecord;
int main() {
size_t n, k;
if(scanf("%zu%zu", &n, &k) != 2) return 0;
string plate, in;
unsigned h, m, s;
vector<Record> records;
for(size_t i = 0; i < n && cin >> plate && scanf("%u:%u:%u", &h, &m, &s) && cin >> in; ++i) {
records.emplace_back(plate, h * 3600 + m * 60 + s, in == "in");
}
sort(records.begin(), records.end());
vector<noPlateRecord> valid;
unordered_map<string, unsigned> parktime;
pair<unsigned, vector<string>> maxParkTime;
for(auto it = records.begin(); it != records.end() - 1; ++it) {
if(!get<2>(*it) || get<2>(*it) == get<2>(*(it+1)) || get<0>(*it) != get<0>(*(it+1))) continue;
valid.emplace_back(get<1>(*it), get<2>(*it));
valid.emplace_back(get<1>(*(it+1)), get<2>(*(it+1)));
unsigned temp = (parktime[get<0>(*it)] += get<1>(*(it+1)) - get<1>(*it));
if(temp > maxParkTime.first) maxParkTime.first = temp;
}
sort(valid.begin(), valid.end());
for(size_t i = 0, j = 0, cnt = 0; i < k && scanf("%u:%u:%u", &h, &m, &s); ++i) {
for(unsigned ts = h * 3600 + m * 60 + s; j < valid.size() && valid[j].first <= ts; ++j) {
cnt += (valid[j].second ? 1 : -1);
}
printf("%zu\n", cnt);
}
for(const auto &kv : parktime) {
if(kv.second == maxParkTime.first) maxParkTime.second.emplace_back(kv.first);
}
sort(maxParkTime.second.begin(), maxParkTime.second.end());
for(const auto &plate : maxParkTime.second) printf("%s ", plate.c_str());
printf("%02u:%02u:%02u\n", maxParkTime.first / 3600, maxParkTime.first / 60 % 60, maxParkTime.first % 60);
return 0;
}