Submission #1039573

# Submission time Handle Problem Language Result Execution time Memory
1039573 2024-07-31T04:44:11 Z 정민찬(#10992) Sprinklers (CEOI24_sprinklers) C++17
100 / 100
574 ms 4372 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N, M;
int s[100010], f[100010];

pair<int,int> ran(int l, int r) {
    int retl = lower_bound(f+1, f+M+1, l) - f;
    int retr = upper_bound(f+1, f+M+1, r) - f - 1;
    return {retl, retr};
}

int dp[100010], prv[100010];

bool solve(int X) {
    dp[0] = 0;
    for (int i=1; i<=N; i++) {
        dp[i] = dp[i-1]; prv[i] = 0;
        int retl, retr;
        tie(retl, retr) = ran(s[i]-X, s[i]);
        if (dp[i-1] >= retl-1) {
            if (dp[i] < retr) {
                dp[i] = retr;
                prv[i] = 1;
            }
        }
        tie(retl, retr) = ran(s[i], s[i]+X);
        if (dp[i-1] >= retl-1) {
            if (dp[i] < retr) {
                dp[i] = retr;
                prv[i] = 2;
            }
        }
        if (i != 1) {
            tie(retl, retr) = ran(s[i] - X, s[i-1] + X);
            if (dp[i-2] >= retl-1) {
                if (dp[i] < retr) {
                    dp[i] = retr;
                    prv[i] = 3;
                }
            }
        }
    }
    return dp[N] == M;
}

int ans[100010];

int main() {
    scanf("%d %d", &N, &M);
    for (int i=1; i<=N; i++) {
        scanf("%d", &s[i]);
    }
    for (int i=1; i<=M; i++) {
        scanf("%d", &f[i]);
    }
    int lo = 0, hi = 1e9 + 10;
    while (lo < hi) {
        int mid = lo + hi >> 1;
        if (solve(mid)) hi = mid;
        else lo = mid + 1;
    }
    if (lo == 1e9 + 10) {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", lo);
    solve(lo);
    int x = N;
    while (x) {
        if (prv[x] <= 1) {
            ans[x] = 0;
            x --;
        }
        else if (prv[x] == 2) {
            ans[x] = 1;
            x --;
        }
        else {
            ans[x] = 0;
            ans[x-1] = 1;
            x -= 2;
        }
    }
    for (int i=1; i<=N; i++) {
        if (ans[i] == 0) printf("L");
        else printf("R");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:61:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |         int mid = lo + hi >> 1;
      |                   ~~~^~~~
Main.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d", &s[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf("%d", &f[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 7 ms 600 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 15 ms 600 KB Correct
5 Correct 8 ms 604 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 2 ms 348 KB Correct
9 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 14 ms 860 KB Correct
3 Correct 36 ms 580 KB Correct
4 Correct 442 ms 2388 KB Correct
5 Correct 463 ms 2236 KB Correct
6 Correct 1 ms 344 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 258 ms 2232 KB Correct
9 Correct 268 ms 2388 KB Correct
10 Correct 308 ms 2388 KB Correct
11 Correct 161 ms 1844 KB Correct
12 Correct 200 ms 1228 KB Correct
13 Correct 361 ms 2128 KB Correct
14 Correct 402 ms 2132 KB Correct
15 Correct 418 ms 2132 KB Correct
16 Correct 383 ms 2128 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 0 ms 344 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 1 ms 348 KB Correct
11 Correct 0 ms 348 KB Correct
12 Correct 1 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 0 ms 444 KB Correct
16 Correct 1 ms 348 KB Correct
17 Correct 0 ms 348 KB Correct
18 Correct 0 ms 348 KB Correct
19 Correct 0 ms 348 KB Correct
20 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 87 ms 948 KB Correct
3 Correct 559 ms 4176 KB Correct
4 Correct 574 ms 4372 KB Correct
5 Correct 542 ms 4180 KB Correct
6 Correct 574 ms 4168 KB Correct
7 Correct 546 ms 4180 KB Correct
8 Correct 541 ms 4180 KB Correct
9 Correct 469 ms 4180 KB Correct
10 Correct 533 ms 4180 KB Correct
11 Correct 528 ms 4180 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 1 ms 348 KB Correct
14 Correct 128 ms 2820 KB Correct
15 Correct 179 ms 2800 KB Correct
16 Correct 182 ms 2900 KB Correct
17 Correct 287 ms 2784 KB Correct
18 Correct 296 ms 3156 KB Correct
19 Correct 388 ms 3156 KB Correct
20 Correct 498 ms 3788 KB Correct
21 Correct 508 ms 3712 KB Correct
22 Correct 463 ms 3664 KB Correct
23 Correct 496 ms 3668 KB Correct
24 Correct 465 ms 3484 KB Correct
25 Correct 440 ms 3412 KB Correct
26 Correct 246 ms 2640 KB Correct
27 Correct 189 ms 1672 KB Correct
28 Correct 435 ms 3152 KB Correct
29 Correct 392 ms 3256 KB Correct
30 Correct 407 ms 3156 KB Correct
31 Correct 397 ms 3160 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 1 ms 348 KB Correct
3 Correct 7 ms 600 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 15 ms 600 KB Correct
6 Correct 8 ms 604 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 2 ms 348 KB Correct
10 Correct 1 ms 348 KB Correct
11 Correct 14 ms 860 KB Correct
12 Correct 36 ms 580 KB Correct
13 Correct 442 ms 2388 KB Correct
14 Correct 463 ms 2236 KB Correct
15 Correct 1 ms 344 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 258 ms 2232 KB Correct
18 Correct 268 ms 2388 KB Correct
19 Correct 308 ms 2388 KB Correct
20 Correct 161 ms 1844 KB Correct
21 Correct 200 ms 1228 KB Correct
22 Correct 361 ms 2128 KB Correct
23 Correct 402 ms 2132 KB Correct
24 Correct 418 ms 2132 KB Correct
25 Correct 383 ms 2128 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 0 ms 344 KB Correct
29 Correct 1 ms 348 KB Correct
30 Correct 0 ms 348 KB Correct
31 Correct 0 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 1 ms 348 KB Correct
34 Correct 0 ms 348 KB Correct
35 Correct 1 ms 348 KB Correct
36 Correct 0 ms 348 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 0 ms 444 KB Correct
39 Correct 1 ms 348 KB Correct
40 Correct 0 ms 348 KB Correct
41 Correct 0 ms 348 KB Correct
42 Correct 0 ms 348 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 87 ms 948 KB Correct
45 Correct 559 ms 4176 KB Correct
46 Correct 574 ms 4372 KB Correct
47 Correct 542 ms 4180 KB Correct
48 Correct 574 ms 4168 KB Correct
49 Correct 546 ms 4180 KB Correct
50 Correct 541 ms 4180 KB Correct
51 Correct 469 ms 4180 KB Correct
52 Correct 533 ms 4180 KB Correct
53 Correct 528 ms 4180 KB Correct
54 Correct 0 ms 348 KB Correct
55 Correct 1 ms 348 KB Correct
56 Correct 128 ms 2820 KB Correct
57 Correct 179 ms 2800 KB Correct
58 Correct 182 ms 2900 KB Correct
59 Correct 287 ms 2784 KB Correct
60 Correct 296 ms 3156 KB Correct
61 Correct 388 ms 3156 KB Correct
62 Correct 498 ms 3788 KB Correct
63 Correct 508 ms 3712 KB Correct
64 Correct 463 ms 3664 KB Correct
65 Correct 496 ms 3668 KB Correct
66 Correct 465 ms 3484 KB Correct
67 Correct 440 ms 3412 KB Correct
68 Correct 246 ms 2640 KB Correct
69 Correct 189 ms 1672 KB Correct
70 Correct 435 ms 3152 KB Correct
71 Correct 392 ms 3256 KB Correct
72 Correct 407 ms 3156 KB Correct
73 Correct 397 ms 3160 KB Correct
74 Correct 28 ms 1628 KB Correct
75 Correct 510 ms 4132 KB Correct
76 Correct 556 ms 4180 KB Correct
77 Correct 1 ms 348 KB Correct
78 Correct 300 ms 4124 KB Correct
79 Correct 313 ms 4184 KB Correct
80 Correct 361 ms 4240 KB Correct
81 Correct 128 ms 2816 KB Correct
82 Correct 173 ms 2796 KB Correct
83 Correct 186 ms 2900 KB Correct
84 Correct 49 ms 1288 KB Correct
85 Correct 450 ms 3356 KB Correct
86 Correct 437 ms 3416 KB Correct
87 Correct 428 ms 3152 KB Correct
88 Correct 9 ms 1628 KB Correct
89 Correct 11 ms 1624 KB Correct