Advertisement
Korotkodul

itmo_gonky

Jan 28th, 2023 (edited)
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 0;
  51.  
  52. struct tim {
  53.     int h, mn, s;
  54.     void see() {
  55.         cout << h << ' ' << mn << ' ' << s << "\n";
  56.     }
  57. };
  58.  
  59. int len(tim x) {
  60.     return 3600 * x.h + 60 * x.mn + x.s;
  61. }
  62.  
  63. bool cmp(tim a, tim b) {
  64.     return len(a) < len(b);
  65. }
  66.  
  67. int f(tim a, tim b) {
  68.     int la = len(a), lb = len(b);
  69.     if (sh) {
  70.         cout << "a b\n";
  71.         a.see();
  72.         b.see();
  73.         cout << "la lb = " << la << ' '<< lb << "\n";
  74.     }
  75.     if (lb - la < 0) {
  76.         lb += 24 * 3600;
  77.     }
  78.     return lb - la;
  79. }
  80.  
  81.  
  82.  
  83. tim con(string T) {
  84.  
  85.    /* if (sh) {
  86.         cout << "time cnt\n";
  87.         cout << T << "\n";
  88.         cout << T[0] << ' ' << T[1] << "\n";
  89.         cout << T[0] + T[1] << "\n";
  90.     }*/
  91.     int h = 10*(T[0]-'0') + T[1]-'0';
  92.     int mn = 10*(T[3] - '0') + T[4] -'0';
  93.     int s = 10*(T[6] - '0') + (T[7] - '0');
  94.     return {h, mn, s};
  95. }
  96.  
  97.  
  98. int main() {
  99.     ios::sync_with_stdio(0);
  100.     cin.tie(0);
  101.     cout.tie(0);
  102.  
  103.     int n, m;
  104.     map <string, pair <tim, tim> > res;
  105.  
  106.     cin >> n >> m;
  107.     for (int i = 0; i < m; ++i) {
  108.         int p;
  109.         cin >> p;
  110.         string nam; cin >> nam;
  111.         if (res.find(nam) == res.end()) {
  112.             res[nam].first = {-1, -1, -1};
  113.             res[nam].second = {-1, -1, -1};
  114.         }
  115.         string Ti; cin >> Ti;
  116.         if (p != 1 && p != n) {
  117.             if (sh) {
  118.                 cout << "skip\n";
  119.             }
  120.             continue;
  121.         }
  122.         tim t = con(Ti);
  123.         if (p == 1) {
  124.             res[nam].first = t;
  125.         } else {
  126.             res[nam].second = t;
  127.         }
  128.         /*if (sh) {
  129.             cout << "Ti = " << Ti << "\n";
  130.             cout << "nam = " << nam << "\n";
  131.             cout << "p = " << p << "\n";
  132.             cout << "tim = "; t.see();
  133.             cout << "\n";
  134.         }*/
  135.     }
  136.  
  137.     if (sh) {
  138.         cout << "res\n";
  139.         for (auto ex: res) {
  140.             cout << ex.first << "\n";
  141.             ex.second.first.see();
  142.             ex.second.second.see();
  143.             cout << "\n";
  144.         }
  145.     }
  146.  
  147.  
  148.     vector < pair <int, string> > srt;
  149.     for (auto ex: res) {
  150.             int l = f(ex.second.first,  ex.second.second);
  151.             if (ex.second.first.h == -1 || ex.second.second.h == -1) {
  152.                 continue;
  153.             }
  154.             srt.push_back({l, ex.first} );
  155.             //ex.second.first.see();
  156.             //ex.second.second.see();
  157.         }
  158.     if (sh) {
  159.         cout << "srt\n";
  160.         for (auto p: srt) {
  161.             cout << p.first << ' ' << p.second << "\n";
  162.         }
  163.     }
  164.     sort(srt.begin(), srt.end());
  165.     vector <string> ans;
  166.     int id = 0;
  167.     while (srt.size() > 0 && id <= srt.size() - 1 && srt[id].first == srt[0].first) {
  168.         ans.push_back(srt[id].second);
  169.         id++;
  170.     }
  171.     cout << ans.size() << "\n";
  172.     cvs(ans);
  173. }
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement