Alex_tz307

Consolidare

Dec 12th, 2020 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("consolidare.in");
  7. ofstream fout("consolidare.out");
  8.  
  9. int32_t main() {
  10.     fin.sync_with_stdio(false);
  11.     fout.sync_with_stdio(false);
  12.     fin.tie(nullptr);
  13.     fout.tie(nullptr);
  14.     int L, H;
  15.     fin >> L >> H;
  16.     vector<vector<bool>> a(H + 1, vector<bool>(L + 1));
  17.     for(int i = 1; i <= L; ++i) {
  18.         int x;
  19.         fin >> x;
  20.         for(int j = H; j > H - x; --j)
  21.             a[j][i] = true;
  22.     }
  23.     int ans = 0;
  24.     for(int i = 1; i <= H; ++i) {
  25.         vector<int> gaps;
  26.         gaps.emplace_back(0);
  27.         for(int j = 1; j <= L; ++j)
  28.             if(!a[i][j])
  29.                 ++gaps.back();
  30.             else
  31.                 if(gaps.back() > 0)
  32.                     gaps.emplace_back(0);
  33.         if(gaps.back() == 0)
  34.             gaps.pop_back();
  35.         int g = 0;
  36.         for(int x : gaps)
  37.             g = __gcd(g, x);
  38.         for(int x : gaps)
  39.             ans += x / g;
  40.     }
  41.     fout << ans;
  42. }
  43.  
Add Comment
Please, Sign In to add comment