mr_dot_convict

11157-Dynamic-Frog-UVa-mr.convict

Jun 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. /*author* Priyanshu Shrivastav (from IIT Palakkad) *
  2.  * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
  3.  * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
  4.  * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
  5.  * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
  6. When I wrote this, only God and I understood what I was doing
  7.  ** * * * * * * * Now, only God knows * * * * * * */
  8. #include         <bits/stdc++.h>
  9. using namespace std;
  10. #pragma GCC      optimize ("Ofast")
  11. #pragma GCC      optimize ("unroll-loops")
  12. #pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  13.  
  14. #define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
  15. #define PREC     cout.precision (10); cout << fixed
  16. #define bg(x)    " [ " << #x << " : " << (x) << " ]"
  17. #define x        first
  18. #define y        second
  19. using ll = long long;
  20.  
  21. #define debug(args...) { \
  22.    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
  23.    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
  24. }
  25. void err(istream_iterator<string> it) { it->empty();
  26.    cerr << " (Line : " << __LINE__ << ")" << '\n';
  27. }
  28. template<typename T, typename... Args>
  29. void err(istream_iterator<string> it, T a, Args... args) {
  30.     cerr << " [ " <<  *it << " : " << a  << " ] "<< ' ';
  31.     err(++it, args...);
  32. }
  33. using ll = long long;
  34. using pib = pair <ll, bool>;
  35.  
  36. vector <pib> stones;
  37. int n;
  38. ll d;
  39. ll solve(int idx) {
  40.    vector <int> next_alt = {idx}, alt = {idx};
  41.    int nxt_idx = idx + 1;
  42.    if (nxt_idx >= n + 2) return 0;
  43.    while(!stones[nxt_idx].y) {
  44.       if ((nxt_idx - idx) & 1) next_alt.push_back(nxt_idx);
  45.       else alt.push_back(nxt_idx);
  46.       ++nxt_idx;
  47.    }
  48.    next_alt.push_back(nxt_idx), alt.push_back(nxt_idx);
  49.  
  50.    ll mx = 0;
  51.    for (int i = 0; i < (int)next_alt.size() - 1; ++i)
  52.       mx = max(mx, stones[next_alt[i+1]].x - stones[next_alt[i]].x);
  53.  
  54.    for (int i = 0; i < (int)alt.size() - 1; ++i)
  55.       mx = max(mx, stones[alt[i+1]].x - stones[alt[i]].x);
  56.  
  57.    return max(mx, solve(nxt_idx));
  58. }
  59.  
  60. void init() {
  61.    stones.clear();
  62. }
  63. void read(int tc) {
  64.    init();
  65.    cin >> n >> d;
  66.    int n_cp = n;
  67.    stones.push_back({0, true});
  68.  
  69.    while (n_cp--) {
  70.       string st; cin >> st; stringstream ss(st);
  71.       char type, dash; int dist; ss >> type >> dash >> dist;
  72.       stones.push_back({dist, type == 'B'});
  73.    }
  74.    stones.push_back({d, true});
  75.    cout << "Case " << tc << ": " << solve(0) << '\n';
  76. }
  77.  
  78. signed main() {
  79.    IOS; PREC;
  80.    int tc; cin >> tc;
  81.    for (int i = 1; i <= tc; ++i) {
  82.       read(i);
  83.    }
  84.  
  85.    return EXIT_SUCCESS;
  86. }
Add Comment
Please, Sign In to add comment