Submission #186828

# Submission time Handle Problem Language Result Execution time Memory
186828 2020-01-12T10:45:09 Z MiricaMatei Strange Device (APIO19_strange_device) C++14
5 / 100
618 ms 61980 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000005;
const long long INF = 1000000000000000000LL;

int l[MAXN], r[MAXN];

int main() {
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);

  long long n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  long long s = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld", &l[i], &r[i]);
    s += (r[i] - l[i] + 1);
  }
  if (a >= INF / b) {
    printf("%lld\n", s);
    return 0;
  }
  long long P = a * b;
  vector<pair<long long, long long> >interval;
  for (int i = 1; i <= n; ++i) {
    long long lg = r[i] - l[i] + 1;
    if (lg >= P) {
      printf("%lld\n", P);
      return 0;
    }
    if (r[i] % P >= l[i] % P) {
      interval.push_back({l[i] % P, r[i] % P});
    } else {
      interval.push_back({0, r[i] % P});
      interval.push_back({l[i] % P, P - 1});
    }
  }
  sort(interval.begin(), interval.end());
  long long mx = 0;
  long long ans = 0;
  for (auto it:interval) {
    //fprintf(stderr, "%lld %lld\n", it.first, it.second);
    ans += max(0LL, it.second - max(it.first, mx) + 1);
    mx = max(mx, it.second + 1);
  }
  printf("%lld\n", ans);

  return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:18:35: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
     scanf("%lld%lld", &l[i], &r[i]);
                       ~~~~~       ^
strange_device.cpp:18:35: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
strange_device.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &n, &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld", &l[i], &r[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 8 ms 1144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 618 ms 61980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 618 ms 61980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 618 ms 61980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 424 KB Output is correct
2 Incorrect 61 ms 7116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Incorrect 8 ms 1144 KB Output isn't correct
3 Halted 0 ms 0 KB -