Submission #351234

# Submission time Handle Problem Language Result Execution time Memory
351234 2021-01-19T16:54:42 Z spatarel Watching (JOI13_watching) C++17
50 / 100
1 ms 620 KB
#include <stdio.h>
#include <algorithm>

const int MAX_N = 2000;

int n, p, q;
int a[MAX_N];

int nextNForW[1 + MAX_N + 1];
int nextNFor2W[1 + MAX_N + 1];
int maxN[1 + MAX_N + 1][1 + MAX_N + 1];

void maxSelf(int &a, int b) {
  if (a < b) {
    a = b;
  }
}

bool isPossible(int w) {
  //printf("w = %d\n", w);
  int i = 1;
  int j = 1;
  while (i <= n) {
    if (j <= n && a[j] <= a[i] + w - 1) {
      j++;
    } else {
      nextNForW[i] = j - 1;
      //printf("%d ", nextNForW[i]);
      i++;
    }
  }
  nextNForW[n + 1] = n;
  //printf("\n");
  i = 1;
  j = 1;
  while (i <= n) {
    if (j <= n && a[j] <= a[i] + 2 * w - 1) {
      j++;
    } else {
      nextNFor2W[i] = j - 1;
      //printf("%d ", nextNFor2W[i]);
      i++;
    }
  }
  nextNFor2W[n + 1] = n;
  //printf("\n");
  
  for (int i = 0; i <= p; i++) {
    for (int j = 0; j <= q; j++) {
      maxN[i][j] = 0;
    }
  }
  for (int i = 0; i <= p; i++) {
    for (int j = 0; j <= q; j++) {
      maxSelf(maxN[i + 1][j], nextNForW[maxN[i][j] + 1]);
      maxSelf(maxN[i][j + 1], nextNFor2W[maxN[i][j] + 1]);
      //printf("%d ", maxN[i][j]);
    }
    //printf("\n");
  }
  return maxN[p][q] == n;
}

int main() {
  scanf("%d%d%d", &n, &p, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  std::sort(a + 1, a + 1 + n);
  int w;
  if (n <= p + q) {
    w = 1;
  } else {
    w = 0;
    for (int step = 1 << 29; step > 0; step >>= 1) {
      if (!isPossible(w + step)) {
        w += step;
      }
    }
    w++;
  }
  printf("%d\n", w);
  return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |   scanf("%d%d%d", &n, &p, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -