Submission #124417

# Submission time Handle Problem Language Result Execution time Memory
124417 2019-07-03T10:10:59 Z AyaBenSaad Strange Device (APIO19_strange_device) C++14
0 / 100
685 ms 32416 KB
#include <bits/stdc++.h>
#define ll long long 
// sub 4
using namespace std;

const int M = 2e6 + 6;
int n;
ll a, b;
stack <pair <ll, ll> > s;
pair <ll, ll> t[M], rem[M];

bool inter (ll a, ll b) {
  ll x = s.top().first;
  ll y = s.top().second;
  return ((a <= y && a >= x) || (b <= y && b >= x));
}
  
int main () {
  scanf ("%d %lld %lld", &n, &a, &b);
  for (int i = 0; i < n; i++) {
    scanf ("%lld %lld", &t[i].first, &t[i].second);
  }
  if (a < 3) {puts("1"); return 0;}
  sort (t, t+n);
  for (int i = 0; i < n; i++) {
    if (s.empty() || !inter(t[i].first, t[i].second)) {
      s.push ({t[i].first, t[i].second});
    }
    else {
      long long x = min (t[i].first, s.top().first);
      long long y = max (t[i].second, s.top().second);
      s.pop();
      s.push({x, y});
    }
  }
  if (a % 2) {
      int k = 0;
      while (s.size()) {
        if (((s.top().second - s.top().first + 1) / a) >= 1) {printf("%lld\n", a); return 0;}
        long long x = s.top().first%a, y = s.top().second%a;
        if (x <= y) {t[k] = {x, y}; k++;}
        else {t[k] = {x, a-1}; k++; t[k] = {0, y}; k++;}
        s.pop();
      }

      sort (t, t+k);
      for (int i = 0; i < k; i++) {
        if (s.empty() || !inter(t[i].first, t[i].second)) {
          s.push ({t[i].first, t[i].second});
        }
        else {
          long long x = min (t[i].first, s.top().first);
          long long y = max (t[i].second, s.top().second);
          s.pop();
          s.push({x, y});
        }
      }
      long long ans = 0;
      long long res = 0;
      while (s.size()) {
        ans += s.top().second-s.top().first+1;
        res += s.top().second-s.top().first+1;
        s.pop();
      }
      printf("%lld\n", ans);
  }
  else {
    int k = 0;
      long long h = a/2;
      while (s.size()) {
        if (((s.top().second - s.top().first + 1) / a) >= 1) {printf("%lld\n", a); return 0;}
        long long x = (2ll * (s.top().first%a)) % a, y = (2ll * (s.top().second%a) ) % a;
        if (x <= y) {t[k] = {x, y}; k++;}
        else {t[k] = {x, a-2}; k++; t[k] = {0, y}; k++;}
        s.pop();
      }

      sort (t, t+k);
      for (int i = 0; i < k; i++) {
        if (s.empty() || !inter(t[i].first, t[i].second)) {
          s.push ({t[i].first, t[i].second});
        }
        else {
          long long x = min (t[i].first, s.top().first);
          long long y = max (t[i].second, s.top().second);
          s.pop();
          s.push({x, y});
        }
      }
      long long ans = 0;
      while (s.size()) {
        if ((s.top().second-s.top().first+1) / h >= 1)  {printf("%lld\n", h); return 0;}
        ans += (s.top().second-s.top().first+1) / 2;
        s.pop();
      }
      printf("%lld\n", ans);
  }
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %lld %lld", &n, &a, &b);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:21:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%lld %lld", &t[i].first, &t[i].second);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 9 ms 632 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Incorrect 6 ms 424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 671 ms 32388 KB Output is correct
3 Incorrect 685 ms 32416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 671 ms 32388 KB Output is correct
3 Incorrect 685 ms 32416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 671 ms 32388 KB Output is correct
3 Incorrect 685 ms 32416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 56 ms 3556 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 9 ms 632 KB Output isn't correct
3 Halted 0 ms 0 KB -