Submission #1039774

# Submission time Handle Problem Language Result Execution time Memory
1039774 2024-07-31T08:49:42 Z 변재우(#10994) Sprinklers (CEOI24_sprinklers) C++17
26 / 100
98 ms 6068 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=100010;
int N, M, ans=-1, Nt, Mt, At[Nmax], Bt[Nmax];
pair<int, int> A[Nmax], B[Nmax];
int X[Nmax];
char ret[Nmax];

bool chk(int K, bool op) {
    N=M=0, fill(X+1, X+Mt+1, 0);
    for(int i=1; i<=Nt; i++) {
        if(i>1 && At[i]==At[i-1]) {
            if(i==2 || At[i-1]!=At[i-2]) {
                N--;
                auto p=lower_bound(Bt+1, Bt+Mt+1, At[i]-K);
                auto q=upper_bound(Bt+1, Bt+Mt+1, At[i]+K);
                X[p-Bt]++, X[q-Bt]--;
                ret[i-1]='L', ret[i]='R';
            }
        }
        else A[++N]={At[i], i};
    }
    for(int i=1; i<=Mt; i++) {
        X[i]+=X[i-1];
        if(!X[i]) B[++M]={Bt[i], i};
    }
    for(int i=1, j=1; i<=M; i++) {
        if(j>N) return false;
        if(A[j].first<=B[i].first) {
            while(j<=N && A[j].first<B[i].first-K) j++;
            if(j>N) return false;
            if(A[j].first>B[i].first) {i--; continue;}
            while(i<=M && B[i].first<=A[j].first+K) i++; i--;
            ret[A[j].second]='R';
            j++; continue;
        }
        int l=j, r=j;
        while(r<N && A[r+1].first<=B[i].first+K) ++r;
        if(A[l].first>B[i].first+K) return false;
        if(r-l+1==1) {
            while(i<=M && B[i].first<=A[j].first) i++; i--;
            ret[A[j].second]='L';
            j++;
            continue;
        }
        if(r-l+1==2) {
            auto p=upper_bound(B+1, B+M+1, make_pair(A[l].first, (int)INT_MAX));
            if(p<=B+M && (*p).first<A[r].first) {
                while(i<=M && B[i].first<=A[l].first+K) i++; i--;
                ret[A[j].second]='R', ret[A[j+1].second]='L';
                j+=2; continue;
            }
            else {
                while(i<=M && B[i].first<=A[r].first+K) i++; i--;
                ret[A[j].second]='L', ret[A[j+1].second]='R';
                j+=2; continue;
            }
        }
        ret[A[l].second]='R', ret[A[l+1].second]='L', ret[A[r].second]='R';
        while(i<=M && B[i].first<=A[r].first+K) i++; i--;
        j=r+1;
    }
    if(op) for(int i=1; i<=Nt; i++) cout<<ret[i];
    return true;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>Nt>>Mt;
    for(int i=1; i<=Nt; i++) cin>>At[i];
    for(int i=1; i<=Mt; i++) cin>>Bt[i];
    fill(ret+1, ret+Nt+1, 'L');
    for(int s=0, e=1e9; s<=e; ) {
        int mid=(s+e)/2;
        if(chk(mid, false)) ans=mid, e=mid-1;
        else s=mid+1;
    }
    if(ans>=0) cout<<ans<<"\n", chk(ans, true);
    else cout<<-1;
    return 0;
}

Compilation message

Main.cpp: In function 'bool chk(long long int, bool)':
Main.cpp:35:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   35 |             while(i<=M && B[i].first<=A[j].first+K) i++; i--;
      |             ^~~~~
Main.cpp:35:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   35 |             while(i<=M && B[i].first<=A[j].first+K) i++; i--;
      |                                                          ^
Main.cpp:43:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   43 |             while(i<=M && B[i].first<=A[j].first) i++; i--;
      |             ^~~~~
Main.cpp:43:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   43 |             while(i<=M && B[i].first<=A[j].first) i++; i--;
      |                                                        ^
Main.cpp:51:17: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   51 |                 while(i<=M && B[i].first<=A[l].first+K) i++; i--;
      |                 ^~~~~
Main.cpp:51:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   51 |                 while(i<=M && B[i].first<=A[l].first+K) i++; i--;
      |                                                              ^
Main.cpp:56:17: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   56 |                 while(i<=M && B[i].first<=A[r].first+K) i++; i--;
      |                 ^~~~~
Main.cpp:56:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   56 |                 while(i<=M && B[i].first<=A[r].first+K) i++; i--;
      |                                                              ^
Main.cpp:62:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   62 |         while(i<=M && B[i].first<=A[r].first+K) i++; i--;
      |         ^~~~~
Main.cpp:62:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   62 |         while(i<=M && B[i].first<=A[r].first+K) i++; i--;
      |                                                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Correct
2 Correct 1 ms 4444 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 9 ms 4952 KB Correct
3 Correct 1 ms 4444 KB Correct
4 Correct 18 ms 4936 KB Correct
5 Correct 14 ms 5164 KB Correct
6 Correct 1 ms 4444 KB Correct
7 Correct 1 ms 4444 KB Correct
8 Correct 3 ms 4444 KB Correct
9 Correct 1 ms 4444 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Correct
2 Correct 10 ms 4952 KB Correct
3 Correct 9 ms 4700 KB Correct
4 Correct 98 ms 6008 KB Correct
5 Correct 98 ms 5976 KB Correct
6 Correct 1 ms 4440 KB Correct
7 Correct 1 ms 4444 KB Correct
8 Correct 21 ms 5976 KB Correct
9 Correct 30 ms 6068 KB Correct
10 Correct 43 ms 5068 KB Correct
11 Correct 23 ms 5424 KB Correct
12 Correct 47 ms 5408 KB Correct
13 Correct 75 ms 5724 KB Correct
14 Correct 74 ms 5724 KB Correct
15 Correct 77 ms 5788 KB Correct
16 Correct 80 ms 5720 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Correct 1 ms 4444 KB Correct
4 Correct 1 ms 4440 KB Correct
5 Correct 1 ms 4444 KB Correct
6 Correct 1 ms 4444 KB Correct
7 Correct 1 ms 4440 KB Correct
8 Correct 1 ms 4444 KB Correct
9 Correct 1 ms 4444 KB Correct
10 Correct 1 ms 4444 KB Correct
11 Correct 1 ms 4444 KB Correct
12 Correct 1 ms 4444 KB Correct
13 Correct 1 ms 4444 KB Correct
14 Correct 1 ms 4440 KB Correct
15 Correct 1 ms 4444 KB Correct
16 Correct 1 ms 4444 KB Correct
17 Correct 1 ms 4440 KB Correct
18 Correct 1 ms 4444 KB Correct
19 Correct 1 ms 4444 KB Correct
20 Correct 1 ms 4444 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Correct
2 Correct 15 ms 5208 KB Correct
3 Correct 43 ms 5976 KB Correct
4 Correct 44 ms 5976 KB Correct
5 Correct 43 ms 5980 KB Correct
6 Correct 45 ms 5980 KB Correct
7 Correct 48 ms 6012 KB Correct
8 Correct 46 ms 6012 KB Correct
9 Correct 45 ms 5980 KB Correct
10 Correct 48 ms 5976 KB Correct
11 Correct 44 ms 5976 KB Correct
12 Correct 1 ms 4444 KB Correct
13 Correct 1 ms 4444 KB Correct
14 Correct 25 ms 5368 KB Correct
15 Correct 13 ms 5464 KB Correct
16 Correct 13 ms 5464 KB Correct
17 Correct 15 ms 5980 KB Correct
18 Correct 18 ms 5980 KB Correct
19 Correct 36 ms 6020 KB Correct
20 Correct 35 ms 5980 KB Correct
21 Correct 35 ms 5980 KB Correct
22 Correct 40 ms 5888 KB Correct
23 Incorrect 36 ms 5976 KB User solution is worse than jury's solution
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Correct 9 ms 4952 KB Correct
4 Correct 1 ms 4444 KB Correct
5 Correct 18 ms 4936 KB Correct
6 Correct 14 ms 5164 KB Correct
7 Correct 1 ms 4444 KB Correct
8 Correct 1 ms 4444 KB Correct
9 Correct 3 ms 4444 KB Correct
10 Correct 1 ms 4444 KB Correct
11 Correct 10 ms 4952 KB Correct
12 Correct 9 ms 4700 KB Correct
13 Correct 98 ms 6008 KB Correct
14 Correct 98 ms 5976 KB Correct
15 Correct 1 ms 4440 KB Correct
16 Correct 1 ms 4444 KB Correct
17 Correct 21 ms 5976 KB Correct
18 Correct 30 ms 6068 KB Correct
19 Correct 43 ms 5068 KB Correct
20 Correct 23 ms 5424 KB Correct
21 Correct 47 ms 5408 KB Correct
22 Correct 75 ms 5724 KB Correct
23 Correct 74 ms 5724 KB Correct
24 Correct 77 ms 5788 KB Correct
25 Correct 80 ms 5720 KB Correct
26 Correct 1 ms 4444 KB Correct
27 Correct 1 ms 4440 KB Correct
28 Correct 1 ms 4444 KB Correct
29 Correct 1 ms 4444 KB Correct
30 Correct 1 ms 4440 KB Correct
31 Correct 1 ms 4444 KB Correct
32 Correct 1 ms 4444 KB Correct
33 Correct 1 ms 4444 KB Correct
34 Correct 1 ms 4444 KB Correct
35 Correct 1 ms 4444 KB Correct
36 Correct 1 ms 4444 KB Correct
37 Correct 1 ms 4440 KB Correct
38 Correct 1 ms 4444 KB Correct
39 Correct 1 ms 4444 KB Correct
40 Correct 1 ms 4440 KB Correct
41 Correct 1 ms 4444 KB Correct
42 Correct 1 ms 4444 KB Correct
43 Correct 1 ms 4444 KB Correct
44 Correct 15 ms 5208 KB Correct
45 Correct 43 ms 5976 KB Correct
46 Correct 44 ms 5976 KB Correct
47 Correct 43 ms 5980 KB Correct
48 Correct 45 ms 5980 KB Correct
49 Correct 48 ms 6012 KB Correct
50 Correct 46 ms 6012 KB Correct
51 Correct 45 ms 5980 KB Correct
52 Correct 48 ms 5976 KB Correct
53 Correct 44 ms 5976 KB Correct
54 Correct 1 ms 4444 KB Correct
55 Correct 1 ms 4444 KB Correct
56 Correct 25 ms 5368 KB Correct
57 Correct 13 ms 5464 KB Correct
58 Correct 13 ms 5464 KB Correct
59 Correct 15 ms 5980 KB Correct
60 Correct 18 ms 5980 KB Correct
61 Correct 36 ms 6020 KB Correct
62 Correct 35 ms 5980 KB Correct
63 Correct 35 ms 5980 KB Correct
64 Correct 40 ms 5888 KB Correct
65 Incorrect 36 ms 5976 KB User solution is worse than jury's solution
66 Halted 0 ms 0 KB -