Advertisement
OIQ

Untitled

OIQ
Jan 22nd, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5.  
  6. using namespace std;
  7. int getn(string s) {
  8.     int n = 0;
  9.     string ans = "";
  10.     for (int i = 0; i < s.size(); i++)
  11.         if (isdigit(s[i]))
  12.             ans.push_back(s[i]);
  13.         else {
  14.             if (n == 0)
  15.                 n += (stoi(ans) - 1) * 3600;
  16.             else
  17.                 n += stoi(ans) * 60;
  18.             ans = "";
  19.         }
  20.  
  21.     n += stoi(ans);
  22.     return n;
  23. }
  24.  
  25. int main() {
  26.  
  27.     int n;
  28.     cin >> n;
  29.     vector <int> a(n);
  30.     for (int i = 0; i < n; i++) {
  31.         string s;
  32.         cin >> s;
  33.         a[i] = getn(s);
  34.     }
  35.     sort(a.begin(), a.end());
  36.     vector <int> dp(43200, 0);
  37.     int ind = 0;
  38.     while (a[ind] == 0)
  39.         ind++;
  40.     for (int i = 0; i < n; i++) {
  41.         if (a[i] != 0)
  42.             dp[0] += 43200 - a[i];
  43.     }
  44.     //int r = dp[0];
  45.     for (int i = 1; i < 43200; i++) {
  46.         int r = dp[i - 1];
  47.         int count = ind;
  48.         while (ind < n && a[ind] == i)
  49.             ind++;
  50.         int d = dp[i - 1] + n - (ind - count) - 43200 * (ind - count);
  51.         dp[i] = d;
  52.     }
  53.  
  54.     int ans = 1e9;
  55.     int t = 0;
  56.     for (int i = 0; i < 43200; i++)
  57.         if (dp[i] < ans) {
  58.             ans = dp[i];
  59.             t = i;
  60.         }
  61.  
  62.     int h = t / 3600;
  63.     int m = (t - h * 3600) / 60;
  64.     int s = (t - h * 3600 - m * 60);
  65.  
  66.     string ss = "";
  67.     h++;
  68.     ss += to_string(h);
  69.     ss += ":";
  70.     if (m < 10) {
  71.         ss += "0";
  72.         ss += to_string(m);
  73.     }
  74.     else ss += to_string(m);
  75.     ss += ":";
  76.     if (s < 10) {
  77.         ss += "0";
  78.         ss += to_string(s);
  79.     }
  80.     else ss += to_string(s);
  81.     cout << ss;
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement