Submission #1042353

# Submission time Handle Problem Language Result Execution time Memory
1042353 2024-08-02T22:42:27 Z erray Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
100 / 100
1717 ms 28156 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/ioi/contests/debug.h"
#else 
  #define debug(...) void(37)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(2 * N), C(N), B(N);
  for (int i = 0; i < 2 * N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> C[i];
  }
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  auto F = [&](int mid) {
    vector<int> ra = A, rb = B, rc = C;
    auto Is_good = [&](vector<int> a, vector<int> x) -> vector<bool> {
      auto Get = [&](bool rev) {
        vector<int> good(N + 1);
        int l = -1, r = 0, p = 0;
        for (int i = 0; i < N; ++i) {
          while (l + 1 < N && a[i] - x[l + 1] > mid) ++l;
          while (r < N && x[r] - a[i] <= mid) ++r;
          if (p == i - 1) ++p;
          while (p > 0 && (!rev ? a[p + N - 1] < a[i] : a[p + N - 1] <= a[i])) --p;
          assert(p == i || (!rev ? a[p + N] < a[i] : a[p + N] <= a[i]));
          assert(p == 0 || (!rev ? a[p + N - 1] >= a[i] : a[p + N - 1] > a[i]));
          if (r - l - 1 < 1) {
            continue;
          }
          int start_good;
          if (i < r) {
            start_good = 0;
          } else if (i - p < r) {
            start_good = i - r + 1;
          } else {
            start_good = N + 1;
          }
          int end_good;
          if (i <= l) {
            end_good = -1;
          } else if (i - p <= l) {
            end_good = i - l - 1;
          } else {
            end_good = i;
          }
          debug(i, l, r, p, start_good, end_good);
          if (start_good <= end_good) {
            good[start_good]++;
            good[end_good + 1]--;
          }
        }
        for (int i = 1; i <= N; ++i) good[i] += good[i - 1];
        return good;
      };
      auto s = Get(false);
      reverse(a.begin(), a.end());
      auto r = Get(true);
      reverse(a.begin(), a.end());

      vector<bool> res(N);
      for (int i = 0; i < N; ++i) {
        res[i] = (s[i] + r[N - i]) == N;
      }
      debug(a, x, s, r, res);

      return res;
    };
    auto b = Is_good(A, B);
    auto c = Is_good(A, C);
    rotate(A.begin(), A.begin() + N, A.end());
    for (auto& x : A) x = -x;  
    for (auto& x : B) x = -x; 
    reverse(B.begin(), B.end());
    for (auto& x : C) x = -x; 
    reverse(C.begin(), C.end());
    auto cyc_b = Is_good(A, C);
    auto cyc_c = Is_good(A, B);
    debug(b, c);
    debug(cyc_b, cyc_c);
    bool good = false;
    for (int i = 0; i < N; ++i) {
      good |= (b[i] && cyc_b[i]) || (c[i] && cyc_c[i]);
    }
    swap(ra, A);
    swap(rb, B);
    swap(rc, C);
    return good;
  };
  int low = 0, high = int(1e9);
  while (low < high) {
    int mid = (low + high) >> 1;
    if (!F(mid)) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << low << '\n';
  debug(A, B, C);
  debug(F(2));
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 7 ms 604 KB Output is correct
27 Correct 8 ms 620 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 11 ms 612 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 6 ms 608 KB Output is correct
36 Correct 10 ms 600 KB Output is correct
37 Correct 5 ms 604 KB Output is correct
38 Correct 9 ms 644 KB Output is correct
39 Correct 6 ms 612 KB Output is correct
40 Correct 5 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1322 ms 15980 KB Output is correct
2 Correct 1116 ms 16008 KB Output is correct
3 Correct 949 ms 20040 KB Output is correct
4 Correct 1320 ms 27528 KB Output is correct
5 Correct 1136 ms 23916 KB Output is correct
6 Correct 33 ms 1192 KB Output is correct
7 Correct 800 ms 28156 KB Output is correct
8 Correct 784 ms 22832 KB Output is correct
9 Correct 1070 ms 27512 KB Output is correct
10 Correct 1239 ms 27648 KB Output is correct
11 Correct 1205 ms 27432 KB Output is correct
12 Correct 1126 ms 25256 KB Output is correct
13 Correct 1075 ms 23944 KB Output is correct
14 Correct 787 ms 27456 KB Output is correct
15 Correct 713 ms 23912 KB Output is correct
16 Correct 778 ms 23940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 7 ms 604 KB Output is correct
27 Correct 8 ms 620 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 11 ms 612 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 6 ms 608 KB Output is correct
36 Correct 10 ms 600 KB Output is correct
37 Correct 5 ms 604 KB Output is correct
38 Correct 9 ms 644 KB Output is correct
39 Correct 6 ms 612 KB Output is correct
40 Correct 5 ms 616 KB Output is correct
41 Correct 1322 ms 15980 KB Output is correct
42 Correct 1116 ms 16008 KB Output is correct
43 Correct 949 ms 20040 KB Output is correct
44 Correct 1320 ms 27528 KB Output is correct
45 Correct 1136 ms 23916 KB Output is correct
46 Correct 33 ms 1192 KB Output is correct
47 Correct 800 ms 28156 KB Output is correct
48 Correct 784 ms 22832 KB Output is correct
49 Correct 1070 ms 27512 KB Output is correct
50 Correct 1239 ms 27648 KB Output is correct
51 Correct 1205 ms 27432 KB Output is correct
52 Correct 1126 ms 25256 KB Output is correct
53 Correct 1075 ms 23944 KB Output is correct
54 Correct 787 ms 27456 KB Output is correct
55 Correct 713 ms 23912 KB Output is correct
56 Correct 778 ms 23940 KB Output is correct
57 Correct 1164 ms 27528 KB Output is correct
58 Correct 1418 ms 23952 KB Output is correct
59 Correct 659 ms 18116 KB Output is correct
60 Correct 1717 ms 27552 KB Output is correct
61 Correct 1402 ms 24052 KB Output is correct
62 Correct 777 ms 20708 KB Output is correct
63 Correct 26 ms 1124 KB Output is correct
64 Correct 1069 ms 28084 KB Output is correct
65 Correct 1092 ms 22892 KB Output is correct
66 Correct 1675 ms 27628 KB Output is correct
67 Correct 750 ms 27600 KB Output is correct
68 Correct 843 ms 27372 KB Output is correct
69 Correct 560 ms 18724 KB Output is correct
70 Correct 861 ms 27792 KB Output is correct
71 Correct 801 ms 27768 KB Output is correct
72 Correct 909 ms 27596 KB Output is correct
73 Correct 895 ms 27500 KB Output is correct
74 Correct 1345 ms 27508 KB Output is correct
75 Correct 902 ms 18720 KB Output is correct
76 Correct 1431 ms 27444 KB Output is correct
77 Correct 785 ms 24036 KB Output is correct