Alhiris

Untitled

Feb 26th, 2021
612
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define st          first
  4. #define nd          second
  5. #define pb          push_back
  6. #define mkp         make_pair
  7. #define lwbnd       lower_bound
  8. #define upbnd       upper_bound
  9. #define FOR(i,a,b)  for(int i=(a);i<=(b);++i)
  10. #define FORS(i,a,b) for(int i=(a);i<(b);++i)
  11. #define ALL(x)      x.begin(),x.end()
  12. #define SZ(x)       ((int)(x).size())
  13. #define MOD         1000000007 //998244353
  14. #define maxn        500005
  15. typedef long long ll;
  16. typedef pair<int,int> PII;
  17. typedef vector<int> VI;
  18. typedef vector<PII> VPII;
  19. const int INF=0x3f3f3f3f;
  20.  
  21. int Duration, Intersections_n, Streets_n, Cars_n, extra;
  22.  
  23. typedef struct {
  24.     int time;
  25.     int in_front;
  26.     int roads_counter;
  27.     int position;
  28.     vector<string> roads;
  29. } Car;
  30.  
  31. typedef struct {
  32.     int start;
  33.     int end;
  34.     int initial_cars;
  35.     int duration;
  36.     int total_cars;
  37.     int total_average;
  38.     string name;
  39. } Street;
  40.  
  41. typedef struct {
  42.     vector<string> inc_streets;
  43. } Intersection;
  44.  
  45. map <string, Street> Streets;
  46. vector<Car> Cars;
  47. vector<Intersection> Intersections;
  48.  
  49. void average() {
  50.     Street str;
  51.     for (auto car : Cars) {
  52.         int time = 0;
  53.         int done = 0;
  54.         for (auto road : car.roads) {
  55.             if (done == 0) {
  56.                 time += car.in_front;
  57.                 done = 1;
  58.                 continue;
  59.             }
  60.             str = Streets[road];
  61.             time += str.duration;
  62.             Streets[road].total_cars += 1;
  63.         }
  64.         for (auto road : car.roads) {
  65.             Streets[road].total_average += time;
  66.         }
  67.         car.time = time;
  68.     }
  69. }
  70.  
  71.  
  72. int main()
  73. {
  74.     cin.tie(0);
  75.     ios_base::sync_with_stdio(0);
  76.     freopen("c.txt","r",stdin);
  77.     freopen("c.out","w",stdout);
  78.  
  79.     int x, y, duration;
  80.     string nm;
  81.  
  82.     cin >> Duration >> Intersections_n >> Streets_n >> Cars_n >> extra;
  83.     Intersections.resize(Intersections_n);
  84.  
  85.     FORS (i, 0, Streets_n) {
  86.         Street str;
  87.         cin >> str.start >> str.end >> str.name >> str.duration;
  88.         str.initial_cars = 0;
  89.         Intersections[str.end].inc_streets.push_back(str.name);
  90.         Streets[str.name] = str;
  91.     }
  92.     FORS (i, 0, Cars_n) {
  93.         Car cr;
  94.         string aux;
  95.         cin >> cr.roads_counter;
  96.         cin >> aux;
  97.         cr.roads.push_back(aux);
  98.         cr.in_front = Streets[aux].initial_cars;
  99.         Streets[aux].initial_cars += 1;
  100.         FORS (i, 1, cr.roads_counter) {
  101.             cin >> aux;
  102.             cr.roads.push_back(aux);
  103.         }
  104.         Cars.push_back(cr);
  105.     }
  106.     average();
  107.     vector<long long> answers[Intersections_n];
  108.     for (int i = 0; i < Intersections.size(); i++) {
  109.         int counter = 0;
  110.         vector<long long> values (Intersections[i].inc_streets.size(), 0LL);
  111.         long long total = 0LL;
  112.         for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
  113.            
  114.             Street street = Streets[Intersections[i].inc_streets[j]];
  115.              if (street.total_cars == 0) {
  116.                 values[j] = -2;
  117.                 continue;
  118.             }
  119.             if (Duration - street.total_average / street.total_cars < 0) {
  120.                 values[j] = -1;
  121.             } else if (street.total_average != 0){
  122.                 values[j] = 1LL * street.total_cars * street.total_cars / street.total_average;
  123.                 total += 1LL * street.total_cars * street.total_cars / street.total_average;
  124.                 counter++;
  125.             }
  126.            
  127.         }
  128.         if (counter == 0 ) {
  129.             Intersections_n--;
  130.             continue;
  131.         }
  132.         for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
  133.             if (values[j] != -1 && values[j] != -2) {
  134.                 values[j] = 1 + (values[j] * 10LL) / (total * Duration);
  135.             }
  136.         }
  137.         for (auto it: values) {
  138.             answers[i].push_back(it);
  139.         }
  140.     }
  141.     cout << Intersections_n << '\n';
  142.     for (int i = 0; i < Intersections.size(); i++) {
  143.         int counter = 0;
  144.         for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
  145.             if(answers[i][j] > 0)
  146.                 counter++;
  147.         }
  148.         if (counter != 0) {
  149.             cout << i << "\n";
  150.             cout << counter << "\n";
  151.             for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
  152.                 if(answers[i][j] > 0)
  153.                     cout << Intersections[i].inc_streets[j] << ' ' <<  answers[i][j] << '\n';
  154.                 else if (answers[i][j] == 0) {
  155.                     cout << Intersections[i].inc_streets[j] << ' ' << '1' << '\n';
  156.                 }
  157.             }
  158.         }
  159.        
  160.     }
  161. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×