답안 #1039641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039641 2024-07-31T06:32:30 Z 정지훈(#11027) Sprinklers (CEOI24_sprinklers) C++17
26 / 100
94 ms 2900 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[in]+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]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 7 ms 1372 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 10 ms 1576 KB Correct
5 Correct 8 ms 1372 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 2 ms 604 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 9 ms 1372 KB Correct
3 Correct 4 ms 604 KB Correct
4 Correct 55 ms 2804 KB Correct
5 Correct 57 ms 2900 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 20 ms 2532 KB Correct
9 Correct 19 ms 2640 KB Correct
10 Correct 22 ms 2644 KB Correct
11 Correct 11 ms 2096 KB Correct
12 Correct 27 ms 1872 KB Correct
13 Correct 31 ms 2136 KB Correct
14 Correct 35 ms 2356 KB Correct
15 Correct 41 ms 2500 KB Correct
16 Correct 29 ms 2392 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 1 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 1 ms 348 KB Correct
10 Correct 1 ms 456 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 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 1 ms 344 KB Correct
20 Correct 1 ms 344 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 24 ms 1652 KB Correct
3 Correct 91 ms 2860 KB Correct
4 Correct 93 ms 2896 KB Correct
5 Correct 90 ms 2848 KB Correct
6 Correct 92 ms 2896 KB Correct
7 Correct 94 ms 2816 KB Correct
8 Correct 88 ms 2896 KB Correct
9 Correct 93 ms 2900 KB Correct
10 Correct 91 ms 2896 KB Correct
11 Correct 91 ms 2768 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 11 ms 1992 KB Correct
15 Correct 13 ms 1964 KB Correct
16 Correct 13 ms 2000 KB Correct
17 Correct 15 ms 2140 KB Correct
18 Correct 16 ms 2136 KB Correct
19 Correct 24 ms 2388 KB Correct
20 Correct 68 ms 2644 KB Correct
21 Correct 67 ms 2644 KB Correct
22 Correct 56 ms 2644 KB Correct
23 Incorrect 58 ms 2616 KB User solution is worse than jury's solution
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 7 ms 1372 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 10 ms 1576 KB Correct
6 Correct 8 ms 1372 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 2 ms 604 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 9 ms 1372 KB Correct
12 Correct 4 ms 604 KB Correct
13 Correct 55 ms 2804 KB Correct
14 Correct 57 ms 2900 KB Correct
15 Correct 1 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 20 ms 2532 KB Correct
18 Correct 19 ms 2640 KB Correct
19 Correct 22 ms 2644 KB Correct
20 Correct 11 ms 2096 KB Correct
21 Correct 27 ms 1872 KB Correct
22 Correct 31 ms 2136 KB Correct
23 Correct 35 ms 2356 KB Correct
24 Correct 41 ms 2500 KB Correct
25 Correct 29 ms 2392 KB Correct
26 Correct 0 ms 348 KB Correct
27 Correct 1 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 1 ms 348 KB Correct
33 Correct 1 ms 456 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 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 1 ms 344 KB Correct
43 Correct 1 ms 344 KB Correct
44 Correct 24 ms 1652 KB Correct
45 Correct 91 ms 2860 KB Correct
46 Correct 93 ms 2896 KB Correct
47 Correct 90 ms 2848 KB Correct
48 Correct 92 ms 2896 KB Correct
49 Correct 94 ms 2816 KB Correct
50 Correct 88 ms 2896 KB Correct
51 Correct 93 ms 2900 KB Correct
52 Correct 91 ms 2896 KB Correct
53 Correct 91 ms 2768 KB Correct
54 Correct 0 ms 348 KB Correct
55 Correct 0 ms 348 KB Correct
56 Correct 11 ms 1992 KB Correct
57 Correct 13 ms 1964 KB Correct
58 Correct 13 ms 2000 KB Correct
59 Correct 15 ms 2140 KB Correct
60 Correct 16 ms 2136 KB Correct
61 Correct 24 ms 2388 KB Correct
62 Correct 68 ms 2644 KB Correct
63 Correct 67 ms 2644 KB Correct
64 Correct 56 ms 2644 KB Correct
65 Incorrect 58 ms 2616 KB User solution is worse than jury's solution
66 Halted 0 ms 0 KB -