답안 #1048075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048075 2024-08-07T21:39:42 Z PurpleCrayon Sprinklers (CEOI24_sprinklers) C++17
26 / 100
151 ms 4944 KB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 1e5+10, MOD = 1e9+7;
const int INF = 2e9+10;
 
void solve() {
    int n, m; cin >> n >> m;
    vector<int> a(n); for (auto& x : a) cin >> x;
    vector<int> b(m); for (auto& x : b) cin >> x;
 
    vector<string> build(n + 1);
    auto can = [&](int x) {
        vector<int> dp(n+1);
        auto upd = [&](int i, int me, string c) {
            if (dp[i] <= me) {
                dp[i] = me;
                build[i] = c;
            }
        };
 
        for (int i = 0; i < n; i++) {
            // dp[i+1] = max(dp[i+1], dp[i]);
            upd(i+1, dp[i], "L");
 
            if (dp[i] >= m) continue;
            int need = b[dp[i]];
            if (a[i] - x <= need && need <= a[i]) {
                int cur = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
                upd(i+1, cur, "L");
                // dp[i+1] = max(dp[i+1], cur);
            }
 
            if (a[i] <= need && need <= a[i] + x) {
                int cur = upper_bound(b.begin(), b.end(), a[i] + x) - b.begin();
                upd(i+1, cur, "R");
                // dp[i+1] = max(dp[i+1], cur);
            }
 
            if (i < n-1) {
                if (a[i+1] - x <= need && need <= a[i] + x) {
                    int cur = upper_bound(b.begin(), b.end(), a[i] + x) - b.begin();
                    upd(i+2, cur, "RL");
                    // dp[i+2] = max(dp[i+2], cur);
                }
            }
        }
 
        return *max_element(dp.begin(), dp.end()) >= m;
    };
 
    int lo = 0, hi = MOD, mid = (lo + hi) / 2;
    while (lo < mid && mid < hi) {
        if (can(mid)) hi = mid;
        else lo = mid;
        mid = (lo + hi) / 2;
    }
 
    if (!can(hi)) {
        cout << -1 << '\n';
        return;
    }
 
    vector<char> ans(n, '?');
    int c = n;
    while (c > 0) {
        string p = build[c];
        if (sz(p) == 1) {
            ans[c-1] = p[0];
            c--;
        } else if (sz(p) == 2) {
            ans[c-1] = p[1];
            ans[c-2] = p[0];
            c -= 2;
        } else assert(false);
    }
 
    vector<int> ps(m + 1);
    for (int i = 0; i < n; i++) {
        int l = -1, r = -1;
        if (ans[i] == 'L') {
            l = a[i] - hi, r = a[i];
        } else if (ans[i] == 'R') {
            l = a[i], r = a[i] + hi;
        } else assert(false);
 
        int L = lower_bound(b.begin(), b.end(), l) - b.begin();
        int R = upper_bound(b.begin(), b.end(), r) - b.begin() - 1;
        if (L <= R) {
            ps[L]++;
            ps[R+1]--;
        }
    }
 
    for (int i = 1; i <= m; i++)
        ps[i] += ps[i-1];
 
    for (int i = 0; i < m; i++) {
        assert(ps[i]);
    }
 
    cout << hi << '\n';
    for (char c : ans) cout << c;
    cout << '\n';
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 5 ms 1116 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 6 ms 860 KB Correct
5 Correct 5 ms 604 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 7 ms 1116 KB Correct
3 Correct 8 ms 856 KB Correct
4 Correct 90 ms 4764 KB Correct
5 Correct 97 ms 4812 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 44 ms 4860 KB Correct
9 Correct 40 ms 4780 KB Correct
10 Correct 40 ms 4812 KB Correct
11 Correct 33 ms 4308 KB Correct
12 Correct 43 ms 2496 KB Correct
13 Correct 73 ms 4564 KB Correct
14 Correct 75 ms 4628 KB Correct
15 Correct 73 ms 4816 KB Correct
16 Correct 65 ms 4632 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 0 ms 348 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 1 ms 348 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 0 ms 348 KB Correct
18 Correct 0 ms 348 KB Correct
19 Correct 0 ms 376 KB Correct
20 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 28 ms 1408 KB Correct
3 Correct 138 ms 4760 KB Correct
4 Correct 145 ms 4944 KB Correct
5 Correct 151 ms 4768 KB Correct
6 Correct 135 ms 4764 KB Correct
7 Correct 139 ms 4768 KB Correct
8 Correct 148 ms 4808 KB Correct
9 Correct 142 ms 4804 KB Correct
10 Correct 141 ms 4812 KB Correct
11 Correct 138 ms 4752 KB Correct
12 Correct 1 ms 344 KB Correct
13 Correct 0 ms 344 KB Correct
14 Incorrect 33 ms 4388 KB User solution is worse than jury's solution
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 5 ms 1116 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 6 ms 860 KB Correct
6 Correct 5 ms 604 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 1 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 7 ms 1116 KB Correct
12 Correct 8 ms 856 KB Correct
13 Correct 90 ms 4764 KB Correct
14 Correct 97 ms 4812 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 44 ms 4860 KB Correct
18 Correct 40 ms 4780 KB Correct
19 Correct 40 ms 4812 KB Correct
20 Correct 33 ms 4308 KB Correct
21 Correct 43 ms 2496 KB Correct
22 Correct 73 ms 4564 KB Correct
23 Correct 75 ms 4628 KB Correct
24 Correct 73 ms 4816 KB Correct
25 Correct 65 ms 4632 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 0 ms 348 KB Correct
29 Correct 0 ms 348 KB Correct
30 Correct 0 ms 348 KB Correct
31 Correct 1 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 0 ms 348 KB Correct
34 Correct 1 ms 348 KB Correct
35 Correct 0 ms 348 KB Correct
36 Correct 0 ms 348 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 0 ms 348 KB Correct
39 Correct 0 ms 348 KB Correct
40 Correct 0 ms 348 KB Correct
41 Correct 0 ms 348 KB Correct
42 Correct 0 ms 376 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 28 ms 1408 KB Correct
45 Correct 138 ms 4760 KB Correct
46 Correct 145 ms 4944 KB Correct
47 Correct 151 ms 4768 KB Correct
48 Correct 135 ms 4764 KB Correct
49 Correct 139 ms 4768 KB Correct
50 Correct 148 ms 4808 KB Correct
51 Correct 142 ms 4804 KB Correct
52 Correct 141 ms 4812 KB Correct
53 Correct 138 ms 4752 KB Correct
54 Correct 1 ms 344 KB Correct
55 Correct 0 ms 344 KB Correct
56 Incorrect 33 ms 4388 KB User solution is worse than jury's solution
57 Halted 0 ms 0 KB -