Submission #1090370

# Submission time Handle Problem Language Result Execution time Memory
1090370 2024-09-18T09:47:19 Z lucri Sprinklers (CEOI24_sprinklers) C++17
100 / 100
82 ms 5708 KB
#include <bits/stdc++.h>
using namespace std;
char ans[100010];
long long ss[100010],ff[100010],n,m,poz1,poz2;
bool verificare2(long long p)
{
    poz1=poz2=1;
    long long elim=-1;
    while(poz2<=m)
    {
        if(poz1>n)
            return false;
        if(ss[poz1]<=ff[poz2])
        {
            elim=ss[poz1]+p;
            ans[poz1-1]='R';
            ++poz1;
        }
        else
        {
            if(ss[poz1]-ff[poz2]>p)
                return false;
            ans[poz1-1]='L';
            elim=ss[poz1];
            if(poz1<n&&ss[poz1+1]-ff[poz2]<=p)
            {
                long long cop=poz2;
                while(cop<=m&&ff[cop]<=ss[poz1])
                    ++cop;
                if(cop<=m&&ff[cop]<ss[poz1+1])
                {
                    ans[poz1-1]='R';
                    ans[poz1]='L';
                    elim=ss[poz1]+p;
                    poz1+=2;
                }
                else
                    ++poz1;
            }
            else
                ++poz1;
        }
        while(poz2<=m&&elim>=ff[poz2])
            ++poz2;
    }
    return true;
}
long long s[100010],f[100010];
bool verificare(long long p)
{
    poz1=poz2=1;
    long long elim=-1;
    while(poz2<=m)
    {
        if(poz1>n)
            return false;
        if(s[poz1]<=f[poz2])
        {
            elim=s[poz1]+p;
            ans[poz1-1]='R';
            ++poz1;
        }
        else
        {
            if(s[poz1]-f[poz2]>p)
                return false;
            ans[poz1-1]='L';
            elim=s[poz1];
            if(poz1<n&&s[poz1+1]-f[poz2]<=p)
            {
                long long cop=poz2;
                while(cop<=m&&f[cop]<=s[poz1])
                    ++cop;
                if(cop<=m&&f[cop]<s[poz1+1])
                {
                    ans[poz1-1]='R';
                    ans[poz1]='L';
                    elim=s[poz1]+p;
                    poz1+=2;
                }
                else
                    ++poz1;
            }
            else
                ++poz1;
        }
        while(poz2<=m&&elim>=f[poz2])
            ++poz2;
    }
    return true;
}
int main()
{
    cin>>n>>m;
    for(long long i=1;i<=n;++i)
    {
        cin>>s[i];
        ss[i]=s[i];
        ans[i-1]='L';
        s[i]=1000000000-s[i];
    }
    for(long long i=1;i<=m;++i)
    {
        cin>>f[i];
        ff[i]=f[i];
        f[i]=1000000000-f[i];
    }
    sort(s+1,s+n+1);
    sort(f+1,f+m+1);
    if(n==1)
    {
        if(f[1]<s[1]&&s[1]<f[m])
        {
            cout<<-1;
            return 0;
        }
    }
    long long b=0,e=2000000000,mid;
    while(b<=e)
    {
        mid=(b+e)/2;
        if(verificare(mid)==true||verificare2(mid)==true)
            e=mid-1;
        else
            b=mid+1;
    }
    if(verificare2(b)==true)
    {
        cout<<b<<'\n'<<ans;
        return 0;
    }
    verificare(b);
    cout<<b<<'\n';
    for(int i=n-1;i>=0;--i)
        if(ans[i]=='R')
            cout<<'L';
        else
            cout<<'R';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 25 ms 2392 KB Correct
3 Correct 1 ms 348 KB Correct
4 Correct 27 ms 2932 KB Correct
5 Correct 26 ms 2900 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 444 KB Correct
8 Correct 6 ms 856 KB Correct
9 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 27 ms 2908 KB Correct
3 Correct 5 ms 856 KB Correct
4 Correct 66 ms 5460 KB Correct
5 Correct 62 ms 5460 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 53 ms 5700 KB Correct
9 Correct 55 ms 5456 KB Correct
10 Correct 54 ms 5460 KB Correct
11 Correct 29 ms 3160 KB Correct
12 Correct 37 ms 3668 KB Correct
13 Correct 37 ms 4176 KB Correct
14 Correct 43 ms 4432 KB Correct
15 Correct 48 ms 4444 KB Correct
16 Correct 36 ms 4176 KB Correct
# Verdict Execution time Memory 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 1 ms 344 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 1 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 1 ms 344 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 0 ms 440 KB Correct
18 Correct 0 ms 348 KB Correct
19 Correct 1 ms 348 KB Correct
20 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 32 ms 3032 KB Correct
3 Correct 73 ms 5456 KB Correct
4 Correct 79 ms 5488 KB Correct
5 Correct 78 ms 5460 KB Correct
6 Correct 73 ms 5608 KB Correct
7 Correct 82 ms 5544 KB Correct
8 Correct 78 ms 5456 KB Correct
9 Correct 72 ms 5464 KB Correct
10 Correct 76 ms 5476 KB Correct
11 Correct 74 ms 5504 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 33 ms 3068 KB Correct
15 Correct 29 ms 3172 KB Correct
16 Correct 29 ms 3156 KB Correct
17 Correct 24 ms 4180 KB Correct
18 Correct 28 ms 4432 KB Correct
19 Correct 38 ms 4632 KB Correct
20 Correct 59 ms 5180 KB Correct
21 Correct 58 ms 5208 KB Correct
22 Correct 51 ms 4944 KB Correct
23 Correct 55 ms 4948 KB Correct
24 Correct 47 ms 4720 KB Correct
25 Correct 47 ms 4692 KB Correct
26 Correct 27 ms 2904 KB Correct
27 Correct 25 ms 2220 KB Correct
28 Correct 46 ms 4200 KB Correct
29 Correct 39 ms 4180 KB Correct
30 Correct 40 ms 4176 KB Correct
31 Correct 41 ms 4440 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 25 ms 2392 KB Correct
4 Correct 1 ms 348 KB Correct
5 Correct 27 ms 2932 KB Correct
6 Correct 26 ms 2900 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 444 KB Correct
9 Correct 6 ms 856 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 27 ms 2908 KB Correct
12 Correct 5 ms 856 KB Correct
13 Correct 66 ms 5460 KB Correct
14 Correct 62 ms 5460 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 53 ms 5700 KB Correct
18 Correct 55 ms 5456 KB Correct
19 Correct 54 ms 5460 KB Correct
20 Correct 29 ms 3160 KB Correct
21 Correct 37 ms 3668 KB Correct
22 Correct 37 ms 4176 KB Correct
23 Correct 43 ms 4432 KB Correct
24 Correct 48 ms 4444 KB Correct
25 Correct 36 ms 4176 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 1 ms 344 KB Correct
29 Correct 1 ms 348 KB Correct
30 Correct 0 ms 348 KB Correct
31 Correct 1 ms 348 KB Correct
32 Correct 1 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 1 ms 344 KB Correct
38 Correct 0 ms 344 KB Correct
39 Correct 0 ms 348 KB Correct
40 Correct 0 ms 440 KB Correct
41 Correct 0 ms 348 KB Correct
42 Correct 1 ms 348 KB Correct
43 Correct 1 ms 348 KB Correct
44 Correct 32 ms 3032 KB Correct
45 Correct 73 ms 5456 KB Correct
46 Correct 79 ms 5488 KB Correct
47 Correct 78 ms 5460 KB Correct
48 Correct 73 ms 5608 KB Correct
49 Correct 82 ms 5544 KB Correct
50 Correct 78 ms 5456 KB Correct
51 Correct 72 ms 5464 KB Correct
52 Correct 76 ms 5476 KB Correct
53 Correct 74 ms 5504 KB Correct
54 Correct 0 ms 348 KB Correct
55 Correct 0 ms 348 KB Correct
56 Correct 33 ms 3068 KB Correct
57 Correct 29 ms 3172 KB Correct
58 Correct 29 ms 3156 KB Correct
59 Correct 24 ms 4180 KB Correct
60 Correct 28 ms 4432 KB Correct
61 Correct 38 ms 4632 KB Correct
62 Correct 59 ms 5180 KB Correct
63 Correct 58 ms 5208 KB Correct
64 Correct 51 ms 4944 KB Correct
65 Correct 55 ms 4948 KB Correct
66 Correct 47 ms 4720 KB Correct
67 Correct 47 ms 4692 KB Correct
68 Correct 27 ms 2904 KB Correct
69 Correct 25 ms 2220 KB Correct
70 Correct 46 ms 4200 KB Correct
71 Correct 39 ms 4180 KB Correct
72 Correct 40 ms 4176 KB Correct
73 Correct 41 ms 4440 KB Correct
74 Correct 30 ms 2900 KB Correct
75 Correct 75 ms 5640 KB Correct
76 Correct 79 ms 5684 KB Correct
77 Correct 1 ms 348 KB Correct
78 Correct 54 ms 5596 KB Correct
79 Correct 54 ms 5524 KB Correct
80 Correct 54 ms 5708 KB Correct
81 Correct 30 ms 3164 KB Correct
82 Correct 29 ms 3116 KB Correct
83 Correct 28 ms 3160 KB Correct
84 Correct 17 ms 1880 KB Correct
85 Correct 49 ms 4284 KB Correct
86 Correct 54 ms 4436 KB Correct
87 Correct 44 ms 4436 KB Correct
88 Correct 31 ms 2908 KB Correct
89 Correct 27 ms 2896 KB Correct