Submission #1323472

#TimeUsernameProblemLanguageResultExecution timeMemory
1323472kizuSprinklers (CEOI24_sprinklers)C++20
9 / 100
41 ms1980 KiB
#include <bits/stdc++.h>

using namespace std ;

#define is ==
#define isnt !=
#define wnsl '\n'
#define ll long long

const ll sec = 4557430888798830399 ;

#define dbg(...) cerr << "(", dbg_out (#__VA_ARGS__, __VA_ARGS__) ;

template <typename... Args>

void print_args (Args... args) {

    ((cout << args << " "), ...) ;

    cout << wnsl ;

}

void dbg_out () {

    cerr << ")" << wnsl ;

}

template <typename Head, typename... Tail>

void dbg_out(const char* names, Head H, Tail... T) {

    const char* comma = strchr (names, ',') ;

    if (!comma) comma = names + strlen(names) ;

    cerr.write (names, comma - names) << " = " << H ;

    if constexpr (sizeof...(T) > 0) {

        cerr << ", " ;

        dbg_out( comma + 1, T...) ;

    } else dbg_out () ;

}

void Solve () {

    ll n, m ;

    cin >> n >> m ;

    ll a [n + 1], b [m + 1] ;

    for (int i = 1 ; i <= n ; i ++) cin >> a [i] ;

    for (int i = 1 ; i <= m ; i ++) cin >> b [i] ;

    ll l = 0, r = sec ;

    while (l < r) {

        ll mid = l + (r - l) / 2 ;

        ll p = 1 ;

        for (int i = 1 ; i <= n ; i ++) {

            if (p <= m and b [p] > a [i] + mid) {

                continue ;

            }

            if (p <= m and b [p] < a [i] - mid) {

                continue ;

            }

            if (p <= m and b [p] < a [i]) {

                while (p <= m and b [p] <= a [i]) p ++ ;

            } else if (p <= m and b [p] >= a [i]) {

                while (p <= m and b [p] - a [i] <= mid) p ++ ;

            }

        }

        if (p > m) r = mid ;

        else l = mid + 1 ;

    }

    if (r is sec) {

        cout << -1 << wnsl ;

        return ;

    } else {

        cout << r << wnsl ;

        ll p = 1 ;

        srand (time (nullptr)) ;

        for (int i = 1 ; i <= n ; i ++) {

            if (p > m) {

                cout << (rand () % 2 is 1 ? 'L' : 'R') ;
                
                continue ;

            }

            if (b [p] < a [i]) {

                cout << 'L' ;

                while (p <= m and b [p] <= a [i]) p ++ ;

            } else {

                cout << 'R' ;

                while (p <= m and b [p] - a [i] <= r) p ++ ;

            }

        }

        cout << wnsl ;

    }

}

int main () {

    ios_base::sync_with_stdio (false) ; cin.tie (nullptr) ; cout.tie (nullptr) ;

    Solve () ;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...