Submission #1038289

# Submission time Handle Problem Language Result Execution time Memory
1038289 2024-07-29T15:43:27 Z ttamx Sprinklers (CEOI24_sprinklers) C++17
100 / 100
83 ms 4944 KB
#include <bits/stdc++.h>

using namespace std;

using P = pair<int,int>;

const int N=1e5+5;
const int INF=INT_MAX/2;

int n,m;
int s[N],f[N];
pair<int,int> dp[N][2];

bool check(int x){
    int a=1,b=1,c=1;
    dp[0][0]=dp[0][1]={1,0};
    for(int i=1;i<=n;i++){
        while(a<=m&&f[a]<=s[i])a++;
        while(b<=m&&f[b]<=s[i-1]+x)b++;
        while(c<=m&&f[c]<=s[i]+x)c++;
        dp[i][0]=dp[i][1]=max(P(dp[i-1][0].first,0),P(dp[i-1][1].first,1));
        if(f[dp[i-1][0].first]>=s[i]-x)dp[i][0]=max(dp[i][0],P(a,0));
        if(f[dp[i-1][1].first]>=s[i]-x)dp[i][0]=max(dp[i][0],P(max(a,b),1));
        if(f[dp[i-1][0].first]>=s[i])dp[i][1]=max(dp[i][1],P(c,0));
        if(f[dp[i-1][1].first]>=s[i])dp[i][1]=max(dp[i][1],P(c,1));
    }
    return max(dp[n][0],dp[n][1]).first>m;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++)cin >> s[i];
    for(int i=1;i<=m;i++)cin >> f[i];
    s[0]=-INF;
    f[m+1]=INF;
    int l=0,r=INF;
    while(l<r){
        int md=(l+r)/2;
        if(check(md))r=md;
        else l=md+1;
    }
    if(l==INF)cout << -1 << "\n";
    else{
        check(l);
        string ans(n,' ');
        for(int i=n,j=dp[n][1]>dp[n][0];i>=1;i--){
            ans[i-1]="LR"[j];
            j=dp[i][j].second;
        }
        cout << l << "\n";
        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Correct
2 Correct 1 ms 2652 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Correct
2 Correct 7 ms 3164 KB Correct
3 Correct 1 ms 2396 KB Correct
4 Correct 11 ms 3392 KB Correct
5 Correct 9 ms 3396 KB Correct
6 Correct 1 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 2 ms 2652 KB Correct
9 Correct 0 ms 2460 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Correct
2 Correct 13 ms 3392 KB Correct
3 Correct 5 ms 2652 KB Correct
4 Correct 53 ms 4700 KB Correct
5 Correct 53 ms 4696 KB Correct
6 Correct 1 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 32 ms 4752 KB Correct
9 Correct 35 ms 4752 KB Correct
10 Correct 47 ms 4696 KB Correct
11 Correct 26 ms 3924 KB Correct
12 Correct 26 ms 3928 KB Correct
13 Correct 45 ms 3924 KB Correct
14 Correct 48 ms 4176 KB Correct
15 Correct 50 ms 4436 KB Correct
16 Correct 44 ms 3924 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Correct
2 Correct 1 ms 2652 KB Correct
3 Correct 1 ms 2396 KB Correct
4 Correct 0 ms 2512 KB Correct
5 Correct 1 ms 2396 KB Correct
6 Correct 0 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 1 ms 2392 KB Correct
9 Correct 1 ms 2396 KB Correct
10 Correct 0 ms 2396 KB Correct
11 Correct 0 ms 2396 KB Correct
12 Correct 1 ms 2396 KB Correct
13 Correct 1 ms 2396 KB Correct
14 Correct 1 ms 2396 KB Correct
15 Correct 1 ms 2396 KB Correct
16 Correct 1 ms 2396 KB Correct
17 Correct 1 ms 2396 KB Correct
18 Correct 1 ms 2396 KB Correct
19 Correct 0 ms 2396 KB Correct
20 Correct 0 ms 2396 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Correct
2 Correct 16 ms 3676 KB Correct
3 Correct 77 ms 4724 KB Correct
4 Correct 80 ms 4696 KB Correct
5 Correct 77 ms 4700 KB Correct
6 Correct 77 ms 4716 KB Correct
7 Correct 75 ms 4712 KB Correct
8 Correct 78 ms 4696 KB Correct
9 Correct 77 ms 4700 KB Correct
10 Correct 77 ms 4700 KB Correct
11 Correct 76 ms 4700 KB Correct
12 Correct 1 ms 2396 KB Correct
13 Correct 0 ms 2392 KB Correct
14 Correct 35 ms 3752 KB Correct
15 Correct 36 ms 3924 KB Correct
16 Correct 28 ms 3932 KB Correct
17 Correct 30 ms 3412 KB Correct
18 Correct 32 ms 3640 KB Correct
19 Correct 38 ms 3752 KB Correct
20 Correct 74 ms 4336 KB Correct
21 Correct 73 ms 4368 KB Correct
22 Correct 73 ms 4220 KB Correct
23 Correct 72 ms 4180 KB Correct
24 Correct 67 ms 3928 KB Correct
25 Correct 66 ms 3932 KB Correct
26 Correct 28 ms 3676 KB Correct
27 Correct 27 ms 3664 KB Correct
28 Correct 60 ms 3856 KB Correct
29 Correct 56 ms 3788 KB Correct
30 Correct 57 ms 3924 KB Correct
31 Correct 39 ms 3932 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Correct
2 Correct 1 ms 2652 KB Correct
3 Correct 7 ms 3164 KB Correct
4 Correct 1 ms 2396 KB Correct
5 Correct 11 ms 3392 KB Correct
6 Correct 9 ms 3396 KB Correct
7 Correct 1 ms 2396 KB Correct
8 Correct 0 ms 2396 KB Correct
9 Correct 2 ms 2652 KB Correct
10 Correct 0 ms 2460 KB Correct
11 Correct 13 ms 3392 KB Correct
12 Correct 5 ms 2652 KB Correct
13 Correct 53 ms 4700 KB Correct
14 Correct 53 ms 4696 KB Correct
15 Correct 1 ms 2396 KB Correct
16 Correct 0 ms 2396 KB Correct
17 Correct 32 ms 4752 KB Correct
18 Correct 35 ms 4752 KB Correct
19 Correct 47 ms 4696 KB Correct
20 Correct 26 ms 3924 KB Correct
21 Correct 26 ms 3928 KB Correct
22 Correct 45 ms 3924 KB Correct
23 Correct 48 ms 4176 KB Correct
24 Correct 50 ms 4436 KB Correct
25 Correct 44 ms 3924 KB Correct
26 Correct 1 ms 2396 KB Correct
27 Correct 0 ms 2512 KB Correct
28 Correct 1 ms 2396 KB Correct
29 Correct 0 ms 2396 KB Correct
30 Correct 0 ms 2396 KB Correct
31 Correct 1 ms 2392 KB Correct
32 Correct 1 ms 2396 KB Correct
33 Correct 0 ms 2396 KB Correct
34 Correct 0 ms 2396 KB Correct
35 Correct 1 ms 2396 KB Correct
36 Correct 1 ms 2396 KB Correct
37 Correct 1 ms 2396 KB Correct
38 Correct 1 ms 2396 KB Correct
39 Correct 1 ms 2396 KB Correct
40 Correct 1 ms 2396 KB Correct
41 Correct 1 ms 2396 KB Correct
42 Correct 0 ms 2396 KB Correct
43 Correct 0 ms 2396 KB Correct
44 Correct 16 ms 3676 KB Correct
45 Correct 77 ms 4724 KB Correct
46 Correct 80 ms 4696 KB Correct
47 Correct 77 ms 4700 KB Correct
48 Correct 77 ms 4716 KB Correct
49 Correct 75 ms 4712 KB Correct
50 Correct 78 ms 4696 KB Correct
51 Correct 77 ms 4700 KB Correct
52 Correct 77 ms 4700 KB Correct
53 Correct 76 ms 4700 KB Correct
54 Correct 1 ms 2396 KB Correct
55 Correct 0 ms 2392 KB Correct
56 Correct 35 ms 3752 KB Correct
57 Correct 36 ms 3924 KB Correct
58 Correct 28 ms 3932 KB Correct
59 Correct 30 ms 3412 KB Correct
60 Correct 32 ms 3640 KB Correct
61 Correct 38 ms 3752 KB Correct
62 Correct 74 ms 4336 KB Correct
63 Correct 73 ms 4368 KB Correct
64 Correct 73 ms 4220 KB Correct
65 Correct 72 ms 4180 KB Correct
66 Correct 67 ms 3928 KB Correct
67 Correct 66 ms 3932 KB Correct
68 Correct 28 ms 3676 KB Correct
69 Correct 27 ms 3664 KB Correct
70 Correct 60 ms 3856 KB Correct
71 Correct 56 ms 3788 KB Correct
72 Correct 57 ms 3924 KB Correct
73 Correct 39 ms 3932 KB Correct
74 Correct 13 ms 3416 KB Correct
75 Correct 82 ms 4700 KB Correct
76 Correct 83 ms 4724 KB Correct
77 Correct 1 ms 2396 KB Correct
78 Correct 32 ms 4700 KB Correct
79 Correct 43 ms 4700 KB Correct
80 Correct 53 ms 4944 KB Correct
81 Correct 27 ms 3932 KB Correct
82 Correct 27 ms 3920 KB Correct
83 Correct 27 ms 3772 KB Correct
84 Correct 11 ms 3164 KB Correct
85 Correct 64 ms 4084 KB Correct
86 Correct 63 ms 4184 KB Correct
87 Correct 43 ms 3932 KB Correct
88 Correct 10 ms 3416 KB Correct
89 Correct 9 ms 3416 KB Correct