Submission #1208172

#TimeUsernameProblemLanguageResultExecution timeMemory
1208172NK_Sprinklers (CEOI24_sprinklers)C++20
6 / 100
45 ms6336 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using str = string; template<class T> using V = vector<T>; // template<class T> using pq = priority_queue<T, vector<T>, greater<T>>; using vs = V<str>; using vi = V<int>; int main() { cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; vi A(N); for(auto& x : A) cin >> x; vi B(M); for(auto& x : B) cin >> x; set<int> has(begin(A), end(A)); { vi C; for(auto& x : B) if (!has.count(x)) C.pb(x); B = C; } M = sz(B); // if (A[0] > B.front() && A[0] < B.back()) { // cout << -1 << nl; // exit(0-0); // } // if (A[0] > B.front()) cout << A[0] - B.front() << nl << "L" << nl; // else cout << B.back() - A[0] << nl << "R" << nl; // exit(0-0); auto chk = [&](int k) { str ans(N, 'L'); int j = 0; for(int i = 0; i < N; i++) { if (j == M) break; // cout << A[i] << " " << B[j] << endl; if (B[j] < A[i] && A[i] - B[j] <= k) { ans[i] = 'L'; while(j < M && B[j] <= A[i]) j++; } else if (A[i] < B[j] && B[j] - A[i] <= k) { ans[i] = 'R'; while(j < M && B[j] - A[i] <= k) j++; } } if (j != M) return str("-1"); return ans; }; int lo = -1, hi = 1e9 + 10; while(lo < hi) { int mid = (lo + hi) / 2; // cout << mid << endl; if (chk(mid) != "-1") hi = mid; else lo = mid + 1; } if (lo == -1) cout << -1 << nl; else { cout << lo << nl; cout << chk(lo) << nl; // assert(lo == max(abs(A.front() - B.front()), abs(A.front() - B.back()))); } exit(0-0); } // Breathe In, Breathe Out
#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...