이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
bool used[N];
int s[N], f[N];
int n, m;
string ans_s = "";
bool ch(int d) {
for (int i = 0; i < (1 << n); i++) {
for (int j = 1; j <= m; j++) {
used[j] = false;
}
for (int j = 1; j <= n; j++) {
if (i & (1 << (j - 1))) {
for (int k = 1; k <= m; k++) {
if (s[j] <= f[k] && f[k] <= s[j] + d) {
used[k] = true;
}
}
}
else {
for (int k = 1; k <= m; k++) {
if (s[j] >= f[k] && f[k] >= s[j] - d) {
used[k] = true;
}
}
}
}
bool ch = true;
for (int j = 1; j <= m; j++) {
ch = min(ch, used[j]);
}
if (ch) {
ans_s.clear();
for (int j = 1; j <= n; j++) {
if (i & (1 << (j - 1))) {
ans_s.push_back('R');
}
else {
ans_s.push_back('L');
}
}
return true;
}
}
return false;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
for (int i = 1; i <= m; i++) {
cin >> f[i];
}
if ((n <= 10 && m <= 1000) || n == 1) {
int l = 0, r = 1e9 + 10, ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (ch(mid)) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans << "\n";
if (ans != -1) cout << ans_s << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |