Submission #1039639

# Submission time Handle Problem Language Result Execution time Memory
1039639 2024-07-31T06:28:29 Z 정지훈(#11027) Sprinklers (CEOI24_sprinklers) C++17
26 / 100
87 ms 1620 KB
#include <bits/stdc++.h>
using namespace std;

int n,m;
int a[100000];
int b[100000];
int pos[100000];

bool func(int k) {
    int ind=0;
    int used=0;
    while (ind<m) {
        int in=lower_bound(a,a+n,b[ind]-k)-a;
        in=max(in,used);
        if (in==n||a[in]>b[ind]+k) {
            return false;
        }
        if (a[in]<=b[ind]) {
            pos[in]=1;
            while (ind<m&&b[ind]<=a[in]+k) {
                ind++;
            }
            used=in+1;
        }
        else {
            if (in!=n-1&&a[in+1]<=b[ind]+k) {
                bool flag=false;
                if (in<n-2&&a[in+2]<=b[ind]+k) {
                    flag=true;
                }
                else {
                    int ind2=lower_bound(b,b+m,a[ind]+1)-b;
                    if (ind2<m&&b[ind2]<a[in+1]) {
                        flag=true;
                    }
                    else {
                        flag=false;
                    }
                }
                if (flag) {
                    while (ind<m&&b[ind]<=a[in]+k) {
                        ind++;
                    }
                    pos[in]=1;
                    pos[in+1]=0;
                    used=in+2;
                }
                else {
                    while (ind<m&&b[ind]<=a[in+1]+k) {
                        ind++;
                    }
                    pos[in]=0;
                    pos[in+1]=1;
                    used=in+2;
                }
            }
            else {
                while (ind<m&&b[ind]<=a[in]) {
                    ind++;
                }
                pos[in]=0;
                used=in+1;
            }
        }
    }
    return true;
}

int main() {
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<m;i++) {
        scanf("%d",&b[i]);
    }
    int lo=-1; //impossible
    int hi=1e9+7; //possible
    if (n==1) {
        int f=-1;
        for(int i=0;i<m;i++) {
            if (b[i]<a[0]) {
                if (f==1) {
                    f=2;
                    break;
                }
                f=0;
            }
            if (b[i]>a[0]) {
                if (f==0) {
                    f=2;
                    break;
                }
                f=1;
            }
        }
        if (f==2) {
            printf("-1");
            return 0;
        }
    }
    while (lo+1<hi) {
        int mid=(lo+hi)/2;
        if (func(mid)) {
            hi=mid;
        }
        else {
            lo=mid;
        }
    }
    func(hi);
    printf("%d\n",hi);
    for(int i=0;i<n;i++) {
        printf("%c",pos[i]?'R':'L');
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         scanf("%d",&b[i]);
      |         ~~~~~^~~~~~~~~~~~
# 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 7 ms 604 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 7 ms 816 KB Correct
5 Correct 8 ms 796 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 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 9 ms 604 KB Correct
3 Correct 4 ms 348 KB Correct
4 Correct 51 ms 1620 KB Correct
5 Correct 56 ms 1616 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 0 ms 344 KB Correct
8 Correct 18 ms 1116 KB Correct
9 Correct 17 ms 1100 KB Correct
10 Correct 19 ms 1372 KB Correct
11 Correct 10 ms 1112 KB Correct
12 Correct 33 ms 976 KB Correct
13 Correct 31 ms 1368 KB Correct
14 Correct 36 ms 1372 KB Correct
15 Correct 43 ms 1456 KB Correct
16 Correct 28 ms 1372 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 600 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 0 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 0 ms 348 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 344 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 1 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 348 KB Correct
20 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 19 ms 860 KB Correct
3 Incorrect 87 ms 1620 KB User solution is incorrect
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 7 ms 604 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 7 ms 816 KB Correct
6 Correct 8 ms 796 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 0 ms 348 KB Correct
11 Correct 9 ms 604 KB Correct
12 Correct 4 ms 348 KB Correct
13 Correct 51 ms 1620 KB Correct
14 Correct 56 ms 1616 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 0 ms 344 KB Correct
17 Correct 18 ms 1116 KB Correct
18 Correct 17 ms 1100 KB Correct
19 Correct 19 ms 1372 KB Correct
20 Correct 10 ms 1112 KB Correct
21 Correct 33 ms 976 KB Correct
22 Correct 31 ms 1368 KB Correct
23 Correct 36 ms 1372 KB Correct
24 Correct 43 ms 1456 KB Correct
25 Correct 28 ms 1372 KB Correct
26 Correct 0 ms 600 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 0 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 0 ms 348 KB Correct
34 Correct 0 ms 348 KB Correct
35 Correct 0 ms 348 KB Correct
36 Correct 0 ms 344 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 1 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 348 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 19 ms 860 KB Correct
45 Incorrect 87 ms 1620 KB User solution is incorrect
46 Halted 0 ms 0 KB -