답안 #1094542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094542 2024-09-29T20:30:41 Z epicci23 Sprinklers (CEOI24_sprinklers) C++17
100 / 100
81 ms 4960 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Correct
2 Correct 1 ms 2396 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Correct
2 Correct 22 ms 2648 KB Correct
3 Correct 1 ms 2392 KB Correct
4 Correct 24 ms 2668 KB Correct
5 Correct 25 ms 2652 KB Correct
6 Correct 0 ms 2396 KB Correct
7 Correct 1 ms 2396 KB Correct
8 Correct 5 ms 2636 KB Correct
9 Correct 1 ms 2396 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Correct
2 Correct 27 ms 2652 KB Correct
3 Correct 5 ms 2396 KB Correct
4 Correct 61 ms 3576 KB Correct
5 Correct 67 ms 3660 KB Correct
6 Correct 1 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 53 ms 3528 KB Correct
9 Correct 56 ms 3616 KB Correct
10 Correct 66 ms 3592 KB Correct
11 Correct 28 ms 3412 KB Correct
12 Correct 38 ms 2904 KB Correct
13 Correct 43 ms 3496 KB Correct
14 Correct 44 ms 3416 KB Correct
15 Correct 48 ms 3416 KB Correct
16 Correct 36 ms 3416 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Correct
2 Correct 1 ms 2396 KB Correct
3 Correct 1 ms 2396 KB Correct
4 Correct 0 ms 2396 KB Correct
5 Correct 1 ms 2396 KB Correct
6 Correct 1 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 1 ms 2396 KB Correct
9 Correct 1 ms 2396 KB Correct
10 Correct 1 ms 2396 KB Correct
11 Correct 1 ms 2392 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 0 ms 2396 KB Correct
16 Correct 1 ms 2396 KB Correct
17 Correct 0 ms 2396 KB Correct
18 Correct 1 ms 2396 KB Correct
19 Correct 1 ms 2396 KB Correct
20 Correct 1 ms 2396 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Correct
2 Correct 30 ms 2764 KB Correct
3 Correct 73 ms 3636 KB Correct
4 Correct 72 ms 3668 KB Correct
5 Correct 72 ms 3636 KB Correct
6 Correct 76 ms 3672 KB Correct
7 Correct 81 ms 3736 KB Correct
8 Correct 71 ms 3664 KB Correct
9 Correct 74 ms 3664 KB Correct
10 Correct 76 ms 3664 KB Correct
11 Correct 75 ms 3668 KB Correct
12 Correct 0 ms 2396 KB Correct
13 Correct 0 ms 2396 KB Correct
14 Correct 27 ms 3344 KB Correct
15 Correct 28 ms 3412 KB Correct
16 Correct 31 ms 3416 KB Correct
17 Correct 23 ms 3572 KB Correct
18 Correct 27 ms 3664 KB Correct
19 Correct 34 ms 3668 KB Correct
20 Correct 58 ms 3520 KB Correct
21 Correct 58 ms 3664 KB Correct
22 Correct 50 ms 3668 KB Correct
23 Correct 60 ms 3540 KB Correct
24 Correct 46 ms 3668 KB Correct
25 Correct 47 ms 3668 KB Correct
26 Correct 27 ms 3164 KB Correct
27 Correct 24 ms 2904 KB Correct
28 Correct 41 ms 3540 KB Correct
29 Correct 38 ms 3420 KB Correct
30 Correct 42 ms 3416 KB Correct
31 Correct 40 ms 3472 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Correct
2 Correct 1 ms 2396 KB Correct
3 Correct 22 ms 2648 KB Correct
4 Correct 1 ms 2392 KB Correct
5 Correct 24 ms 2668 KB Correct
6 Correct 25 ms 2652 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 1 ms 2396 KB Correct
9 Correct 5 ms 2636 KB Correct
10 Correct 1 ms 2396 KB Correct
11 Correct 27 ms 2652 KB Correct
12 Correct 5 ms 2396 KB Correct
13 Correct 61 ms 3576 KB Correct
14 Correct 67 ms 3660 KB Correct
15 Correct 1 ms 2396 KB Correct
16 Correct 0 ms 2396 KB Correct
17 Correct 53 ms 3528 KB Correct
18 Correct 56 ms 3616 KB Correct
19 Correct 66 ms 3592 KB Correct
20 Correct 28 ms 3412 KB Correct
21 Correct 38 ms 2904 KB Correct
22 Correct 43 ms 3496 KB Correct
23 Correct 44 ms 3416 KB Correct
24 Correct 48 ms 3416 KB Correct
25 Correct 36 ms 3416 KB Correct
26 Correct 1 ms 2396 KB Correct
27 Correct 0 ms 2396 KB Correct
28 Correct 1 ms 2396 KB Correct
29 Correct 1 ms 2396 KB Correct
30 Correct 0 ms 2396 KB Correct
31 Correct 1 ms 2396 KB Correct
32 Correct 1 ms 2396 KB Correct
33 Correct 1 ms 2396 KB Correct
34 Correct 1 ms 2392 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 0 ms 2396 KB Correct
39 Correct 1 ms 2396 KB Correct
40 Correct 0 ms 2396 KB Correct
41 Correct 1 ms 2396 KB Correct
42 Correct 1 ms 2396 KB Correct
43 Correct 1 ms 2396 KB Correct
44 Correct 30 ms 2764 KB Correct
45 Correct 73 ms 3636 KB Correct
46 Correct 72 ms 3668 KB Correct
47 Correct 72 ms 3636 KB Correct
48 Correct 76 ms 3672 KB Correct
49 Correct 81 ms 3736 KB Correct
50 Correct 71 ms 3664 KB Correct
51 Correct 74 ms 3664 KB Correct
52 Correct 76 ms 3664 KB Correct
53 Correct 75 ms 3668 KB Correct
54 Correct 0 ms 2396 KB Correct
55 Correct 0 ms 2396 KB Correct
56 Correct 27 ms 3344 KB Correct
57 Correct 28 ms 3412 KB Correct
58 Correct 31 ms 3416 KB Correct
59 Correct 23 ms 3572 KB Correct
60 Correct 27 ms 3664 KB Correct
61 Correct 34 ms 3668 KB Correct
62 Correct 58 ms 3520 KB Correct
63 Correct 58 ms 3664 KB Correct
64 Correct 50 ms 3668 KB Correct
65 Correct 60 ms 3540 KB Correct
66 Correct 46 ms 3668 KB Correct
67 Correct 47 ms 3668 KB Correct
68 Correct 27 ms 3164 KB Correct
69 Correct 24 ms 2904 KB Correct
70 Correct 41 ms 3540 KB Correct
71 Correct 38 ms 3420 KB Correct
72 Correct 42 ms 3416 KB Correct
73 Correct 40 ms 3472 KB Correct
74 Correct 27 ms 2648 KB Correct
75 Correct 75 ms 3664 KB Correct
76 Correct 72 ms 3664 KB Correct
77 Correct 0 ms 2396 KB Correct
78 Correct 65 ms 3668 KB Correct
79 Correct 54 ms 3668 KB Correct
80 Correct 53 ms 3668 KB Correct
81 Correct 28 ms 3344 KB Correct
82 Correct 32 ms 3408 KB Correct
83 Correct 28 ms 3412 KB Correct
84 Correct 16 ms 2648 KB Correct
85 Correct 46 ms 3540 KB Correct
86 Correct 55 ms 4960 KB Correct
87 Correct 41 ms 4748 KB Correct
88 Correct 27 ms 3668 KB Correct
89 Correct 29 ms 3676 KB Correct