# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1070229 | YassineBenYounes | Sprinklers (CEOI24_sprinklers) | C++17 | 2040 ms | 2260 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int >
#define vii vector<pii>
#define ff first
#define ss second
#define pb push_back
#define int ll
const int mx = 1e5+5;
int n, m;
vi s, f;
bool dp[mx][2];
bool check(int k){
memset(dp, 0, sizeof dp);
if(f[0] < s[0]){
dp[0][0] = 0;
}
else{
dp[0][0] = 1;
}
int cur = s[0]-k;
if(f[0] < cur)dp[0][1] = 0;
else dp[0][1] = 1;
for(int i = 1; i < n;i++){
/// go front
bool worse = 0;
for(int x : f){
if(x > s[i-1] && x < s[i]){worse=1;break;}
}
if(worse){
dp[i][0] = 0;
}
else{
dp[i][0] |= dp[i-1][1];
dp[i][0] |= dp[i-1][0];
}
//// go back
worse = 0;
for(int x : f){
if(x > s[i-1] && x < (s[i] - k)){worse=1;break;}
}
if(worse){
bool can = 1;
for(int x : f){
if(x > (s[i-1]+k) && x < (s[i] - k)){can = 0;break;}
}
if(can){
dp[i][1] |= dp[i-1][0];
}
else{
dp[i][1] = 0;
}
}
else{
dp[i][1] |= dp[i-1][0];
dp[i][1] |= dp[i-1][1];
}
}
if(f[m-1] > s[n-1]){
if(f[m-1] > (s[n-1]+k))return 0;
else{
return dp[n-1][0];
}
}
else{
return (dp[n-1][0] | dp[n-1][1]);
}
}
string res;
void construct(int k){
bool x = check(k);
for(int i = 0; i < n;i++){
//cout << dp[i][0] << " " << dp[i][1] << endl;
}
for(int i = n-1; i >= 0;i--){
if(dp[i][0]){
res[i] = 'R';
}
else{
res[i] = 'L';
}
}
}
int32_t main(){
cin >> n >> m;
for(int i = 0; i < n;i++){
int a;cin >> a;
s.pb(a);
}
for(int i = 0; i < m;i++){
int a;cin >> a;
f.pb(a);
}
int l = 0, r = 1e9;
int ans = -1;
while(l <= r){
int md = (l+r)/2;
bool x = check(md);
if(x){
ans = md;
r = md-1;
}
else{
l = md+1;
}
}
//int ans = 3;
cout << ans << endl;
if(ans != -1){
res.resize(n, ' ');
construct(ans);
cout << res << endl;
}
}
Compilation message (stderr)
# | 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... |