#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=100007;
ll n,m,k;
int f[N],s[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("Finput.txt","r",stdin);
// freopen("Foutput.txt","w",stdout);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>s[i];
}
for(int i=0;i<m;i++){
cin>>f[i];
}
int ans=MOD;
int ansmsk=0;
for(int msk=0;msk<(1<<n);msk++){
int curmax=0;
for(int j=0;j<m;j++){
int cur=MOD;
for(int i=0;i<n;i++){
if(
(
(msk&(1<<i)) && s[i]<=f[j]
)||(
(!(msk&(1<<i))) && s[i]>=f[j]
)
){
cur=min(cur,abs(s[i]-f[j]));
}
}
curmax=max(curmax, cur);
}
if(ans>curmax){
ans=curmax;
ansmsk=msk;
}
}
if(ans==MOD){
cout<<-1<<endl;
return 0;
}
cout<<ans<<endl;
for(int i=0;i<n;i++){
if(ansmsk&(1<<i)){
cout<<"R";
}
else{
cout<<"L";
}
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
5 ms |
604 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
6 ms |
1628 KB |
Correct |
5 |
Correct |
6 ms |
1756 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
1 ms |
604 KB |
Correct |
9 |
Correct |
1 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Execution timed out |
2041 ms |
604 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
5 ms |
348 KB |
Correct |
4 |
Correct |
0 ms |
468 KB |
Correct |
5 |
Correct |
10 ms |
348 KB |
Correct |
6 |
Correct |
10 ms |
480 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
9 ms |
480 KB |
Correct |
9 |
Correct |
10 ms |
480 KB |
Correct |
10 |
Correct |
10 ms |
484 KB |
Correct |
11 |
Correct |
2 ms |
348 KB |
Correct |
12 |
Correct |
9 ms |
348 KB |
Correct |
13 |
Correct |
9 ms |
348 KB |
Correct |
14 |
Correct |
1 ms |
348 KB |
Correct |
15 |
Correct |
6 ms |
464 KB |
Correct |
16 |
Correct |
9 ms |
348 KB |
Correct |
17 |
Correct |
7 ms |
344 KB |
Correct |
18 |
Correct |
6 ms |
348 KB |
Correct |
19 |
Correct |
0 ms |
348 KB |
Correct |
20 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Execution timed out |
2059 ms |
860 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
5 ms |
604 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
6 ms |
1628 KB |
Correct |
6 |
Correct |
6 ms |
1756 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
1 ms |
604 KB |
Correct |
10 |
Correct |
1 ms |
348 KB |
Correct |
11 |
Execution timed out |
2041 ms |
604 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |