Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- bool sh = 0;
- struct tim {
- int h, mn, s;
- void see() {
- cout << h << ' ' << mn << ' ' << s << "\n";
- }
- };
- int len(tim x) {
- return 3600 * x.h + 60 * x.mn + x.s;
- }
- bool cmp(tim a, tim b) {
- return len(a) < len(b);
- }
- int f(tim a, tim b) {
- int la = len(a), lb = len(b);
- if (sh) {
- cout << "a b\n";
- a.see();
- b.see();
- cout << "la lb = " << la << ' '<< lb << "\n";
- }
- if (lb - la < 0) {
- lb += 24 * 3600;
- }
- return lb - la;
- }
- tim con(string T) {
- /* if (sh) {
- cout << "time cnt\n";
- cout << T << "\n";
- cout << T[0] << ' ' << T[1] << "\n";
- cout << T[0] + T[1] << "\n";
- }*/
- int h = 10*(T[0]-'0') + T[1]-'0';
- int mn = 10*(T[3] - '0') + T[4] -'0';
- int s = 10*(T[6] - '0') + (T[7] - '0');
- return {h, mn, s};
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- map <string, pair <tim, tim> > res;
- cin >> n >> m;
- for (int i = 0; i < m; ++i) {
- int p;
- cin >> p;
- string nam; cin >> nam;
- if (res.find(nam) == res.end()) {
- res[nam].first = {-1, -1, -1};
- res[nam].second = {-1, -1, -1};
- }
- string Ti; cin >> Ti;
- if (p != 1 && p != n) {
- if (sh) {
- cout << "skip\n";
- }
- continue;
- }
- tim t = con(Ti);
- if (p == 1) {
- res[nam].first = t;
- } else {
- res[nam].second = t;
- }
- /*if (sh) {
- cout << "Ti = " << Ti << "\n";
- cout << "nam = " << nam << "\n";
- cout << "p = " << p << "\n";
- cout << "tim = "; t.see();
- cout << "\n";
- }*/
- }
- if (sh) {
- cout << "res\n";
- for (auto ex: res) {
- cout << ex.first << "\n";
- ex.second.first.see();
- ex.second.second.see();
- cout << "\n";
- }
- }
- vector < pair <int, string> > srt;
- for (auto ex: res) {
- int l = f(ex.second.first, ex.second.second);
- if (ex.second.first.h == -1 || ex.second.second.h == -1) {
- continue;
- }
- srt.push_back({l, ex.first} );
- //ex.second.first.see();
- //ex.second.second.see();
- }
- if (sh) {
- cout << "srt\n";
- for (auto p: srt) {
- cout << p.first << ' ' << p.second << "\n";
- }
- }
- sort(srt.begin(), srt.end());
- vector <string> ans;
- int id = 0;
- while (srt.size() > 0 && id <= srt.size() - 1 && srt[id].first == srt[0].first) {
- ans.push_back(srt[id].second);
- id++;
- }
- cout << ans.size() << "\n";
- cvs(ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement