Submission #1114475

# Submission time Handle Problem Language Result Execution time Memory
1114475 2024-11-19T01:17:27 Z dynam1c Sprinklers (CEOI24_sprinklers) C++17
9 / 100
203 ms 1352 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), f(m);
  for (int& e : s)
    cin >> e;
  for (int& e : f)
    cin >> e;

  vector<char> d(n);
  auto check = [&](int k) {
    d.assign(n, 0);
    int x = -1;
    int j = 0, pj = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] <= x)
        x = s[i]+k, d[i] = 'R', pj = j;
      else if (j < m && f[j] < s[i]) {
        if (s[i]-f[j] > k)
          return false;
        x = s[i], d[i] = 'L';
        if (i > 0 && d[i-1] == 'L' && s[i]-k <= f[pj]) {
          x = s[i-1]+k;
          d[i-1] = 'R';
        }
      } else
        x = s[i]+k, d[i] = 'R', pj = j;
      while (j < m && f[j] <= x)
        j++;
    }
    return j == m;
  };

  if (!check(1e9)) {
    cout << -1 << endl;
    return 0;
  }

  int l = -1, r = 1e9;
  while (r-l > 1) {
    int m = (l+r)/2;
    if (check(m))
      r = m;
    else
      l = m;
  }

  check(r);

  for (int i = 0; i < n; i++)
    if (d[i] == 'L')
      s[i] -= r;
  sort(s.begin(), s.end());
  int j = 0;
  for (int e : s) {
    if (j == m)
      break;
    assert(e <= f[j]);
    while (j < m && f[j] <= e+r)
      j++;
  }
  //assert(j == m);

  cout << r << endl;
  for (char c : d)
    cout << c;
  cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 21 ms 592 KB Correct
3 Correct 1 ms 512 KB Correct
4 Correct 26 ms 592 KB Correct
5 Correct 24 ms 592 KB Correct
6 Correct 1 ms 336 KB Correct
7 Correct 1 ms 336 KB Correct
8 Correct 6 ms 336 KB Correct
9 Correct 1 ms 336 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 26 ms 592 KB Correct
3 Correct 6 ms 336 KB Correct
4 Correct 64 ms 1216 KB Correct
5 Correct 75 ms 1352 KB Correct
6 Correct 1 ms 336 KB Correct
7 Correct 1 ms 336 KB Correct
8 Correct 203 ms 1352 KB Correct
9 Correct 55 ms 1268 KB Correct
10 Correct 84 ms 1352 KB Correct
11 Correct 36 ms 820 KB Correct
12 Correct 39 ms 848 KB Correct
13 Correct 45 ms 1116 KB Correct
14 Correct 56 ms 1188 KB Correct
15 Correct 55 ms 1096 KB Correct
16 Correct 53 ms 1096 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
3 Correct 1 ms 336 KB Correct
4 Correct 1 ms 336 KB Correct
5 Incorrect 1 ms 336 KB User solution is worse than jury's solution
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 33 ms 868 KB Correct
3 Incorrect 84 ms 1352 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
3 Correct 21 ms 592 KB Correct
4 Correct 1 ms 512 KB Correct
5 Correct 26 ms 592 KB Correct
6 Correct 24 ms 592 KB Correct
7 Correct 1 ms 336 KB Correct
8 Correct 1 ms 336 KB Correct
9 Correct 6 ms 336 KB Correct
10 Correct 1 ms 336 KB Correct
11 Correct 26 ms 592 KB Correct
12 Correct 6 ms 336 KB Correct
13 Correct 64 ms 1216 KB Correct
14 Correct 75 ms 1352 KB Correct
15 Correct 1 ms 336 KB Correct
16 Correct 1 ms 336 KB Correct
17 Correct 203 ms 1352 KB Correct
18 Correct 55 ms 1268 KB Correct
19 Correct 84 ms 1352 KB Correct
20 Correct 36 ms 820 KB Correct
21 Correct 39 ms 848 KB Correct
22 Correct 45 ms 1116 KB Correct
23 Correct 56 ms 1188 KB Correct
24 Correct 55 ms 1096 KB Correct
25 Correct 53 ms 1096 KB Correct
26 Correct 1 ms 336 KB Correct
27 Correct 1 ms 336 KB Correct
28 Incorrect 1 ms 336 KB User solution is worse than jury's solution
29 Halted 0 ms 0 KB -