답안 #1039566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039566 2024-07-31T04:37:05 Z 변재우(#10994) Sprinklers (CEOI24_sprinklers) C++17
9 / 100
101 ms 6032 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};
    }
    string s;
    for(int i=1, j=1; i<=M; i++) {
        bool flag=false;
        while(j<=N && !flag) {
            flag|=(abs(B[i].first-A[j].first)<=K);
            if(A[j]<=B[i]) {
                ret[A[j].second]='R';
                while(i<=M && B[i].first-A[j].first<=K) i++; i--;
            }
            else {
                ret[A[j].second]='L';
                while(i<=M && A[j].first-B[i].first>=0) i++; i--;
            }
            j++;
        }
        if(!flag) return false;
    }
    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;
    }
    cout<<ans<<"\n";
    if(ans>=0) chk(ans, true);
    return 0;
}

Compilation message

Main.cpp: In function 'bool chk(long long int, bool)':
Main.cpp:36:17: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   36 |                 while(i<=M && B[i].first-A[j].first<=K) i++; i--;
      |                 ^~~~~
Main.cpp:36:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   36 |                 while(i<=M && B[i].first-A[j].first<=K) i++; i--;
      |                                                              ^
Main.cpp:40:17: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   40 |                 while(i<=M && A[j].first-B[i].first>=0) i++; i--;
      |                 ^~~~~
Main.cpp:40:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   40 |                 while(i<=M && A[j].first-B[i].first>=0) i++; i--;
      |                                                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 1 ms 4444 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 10 ms 4956 KB Correct
3 Correct 1 ms 4444 KB Correct
4 Correct 11 ms 4956 KB Correct
5 Correct 20 ms 4952 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 15 ms 4952 KB Correct
3 Correct 8 ms 4700 KB Correct
4 Correct 101 ms 6032 KB Correct
5 Correct 98 ms 4264 KB Correct
6 Correct 1 ms 4440 KB Correct
7 Correct 1 ms 4444 KB Correct
8 Correct 41 ms 5980 KB Correct
9 Correct 31 ms 5976 KB Correct
10 Correct 44 ms 5980 KB Correct
11 Correct 25 ms 5456 KB Correct
12 Correct 44 ms 5212 KB Correct
13 Correct 70 ms 5772 KB Correct
14 Correct 73 ms 5724 KB Correct
15 Correct 75 ms 5720 KB Correct
16 Correct 63 ms 5724 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Incorrect 1 ms 4440 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Incorrect 16 ms 5212 KB User solution is incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Correct 10 ms 4956 KB Correct
4 Correct 1 ms 4444 KB Correct
5 Correct 11 ms 4956 KB Correct
6 Correct 20 ms 4952 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 15 ms 4952 KB Correct
12 Correct 8 ms 4700 KB Correct
13 Correct 101 ms 6032 KB Correct
14 Correct 98 ms 4264 KB Correct
15 Correct 1 ms 4440 KB Correct
16 Correct 1 ms 4444 KB Correct
17 Correct 41 ms 5980 KB Correct
18 Correct 31 ms 5976 KB Correct
19 Correct 44 ms 5980 KB Correct
20 Correct 25 ms 5456 KB Correct
21 Correct 44 ms 5212 KB Correct
22 Correct 70 ms 5772 KB Correct
23 Correct 73 ms 5724 KB Correct
24 Correct 75 ms 5720 KB Correct
25 Correct 63 ms 5724 KB Correct
26 Incorrect 1 ms 4440 KB User solution is worse than jury's solution
27 Halted 0 ms 0 KB -