Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> pii;
  7.  
  8. #define REP(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
  9.  
  10. int cam, jam;
  11. int day[3000];
  12. int forceL[3000];
  13. int forceR[3000];
  14. int day_start;
  15. int cam_time, jam_time;
  16.  
  17. void read() {
  18.     memset(day,0,sizeof(day));
  19.     cam_time = jam_time = 0;
  20.  
  21.     scanf("%d %d", &cam, &jam);
  22.     for (int i = 0; i < cam; i++) {
  23.         int st, ed;
  24.         scanf("%d %d", &st, &ed);
  25.         day_start = ed;
  26.  
  27.         for (int j = st; j < ed; j++) {
  28.             day[j] = day[j+1440] = 1;
  29.         }
  30.  
  31.         cam_time += ed-st;
  32.     }
  33.  
  34.     for (int i = 0; i < jam; i++) {
  35.         int st, ed;
  36.         scanf("%d %d", &st, &ed);
  37.         day_start = ed;
  38.  
  39.         for (int j = st; j < ed; j++) {
  40.             day[j] = day[j+1440] = 2;
  41.         }
  42.  
  43.         jam_time += ed-st;
  44.     }
  45. }
  46.  
  47. void solve() {
  48.     int switches = 0;
  49.     int la = -1;
  50.  
  51.     vector<int> caam;
  52.     vector<int> jaam;
  53.     int miiix = 0;
  54.  
  55.     for (int i = day_start; i < day_start + 1440; i++) {
  56.         if (day[i] == 1 && day[i-1] != 1) switches++;
  57.         if (day[i] != 1 && day[i-1] == 1) switches++;
  58.  
  59.         if (day[i] == 0) {
  60.             if (day[i-1] != 0) la = i;
  61.             if (day[i+1] != 0) {
  62.                 if (day[la-1] != day[i+1]) miiix += i-la+1;
  63.                 else if (day[la-1] == 1) caam.push_back(i-la+1);
  64.                 else jaam.push_back(i-la+1);
  65.             }
  66.         }
  67.     }
  68.  
  69.     sort(caam.begin(), caam.end());
  70.     sort(jaam.begin(), jaam.end());
  71.  
  72.     int need = 720 - cam_time;
  73.     while (need > 0) {
  74.         if (!caam.empty()) {
  75.             int t = caam.front();
  76.             if (need >= t) {
  77.                 need -= t;
  78.                 switches -= 2;
  79.             }
  80.             else need = 0;
  81.             caam.erase(caam.begin());
  82.         }
  83.  
  84.         else if (miiix) {
  85.             need -= miiix;
  86.             miiix = 0;
  87.         }
  88.  
  89.         else {
  90.             int t = jaam.back();
  91.             need -= t;
  92.             switches += 2;
  93.             jaam.erase(--jaam.end());
  94.         }
  95.     }
  96.  
  97.     printf("%d\n", switches);
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. int myMod = 0;
  126. int howMany = 1;
  127.  
  128. int main(int argc, char** argv) {
  129.     if (argc > 1) {
  130.         stringstream ss; ss << argv[1]; ss >> myMod;
  131.         ss.str(""); ss.clear();
  132.         ss << argv[2]; ss >> howMany;
  133.     }
  134.  
  135.     int cases;
  136.     scanf("%d", &cases);
  137.     for (int i = 0; i < cases; i++) {
  138.         read();
  139.         if (i % howMany == myMod) {
  140.             printf("Case #%d: ", i+1);
  141.             solve();
  142.         }
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement