# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1134906 | 8pete8 | Sprinklers (CEOI24_sprinklers) | C++20 | 484 ms | 7500 KiB |
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,w,h,l;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int F[mxn+10],S[mxn+10],mid,di[mxn+10];
bool check(){
set<int>have;
for(int i=1;i<=m;i++)have.insert(F[i]);
for(int i=1;i<=n;i++){
if(have.empty())return 1;
int mn=(*have.begin());
if(mn<S[i]-mid)return 0;
//forced cases
if(mn>=S[i])di[i]=1;
else if((S[i]-mid)<=mn&&(S[i+1]-mid)>mn)di[i]=0;
else{
auto it=have.upper_bound(S[i]);
//if no flower are in between LR
if(it==have.end()||(*it)>=S[i+1])di[i]=0;
else di[i]=1;
}
if(di[i]==0){
while(have.size()&&(*have.begin())>=(S[i]-mid)&&(*have.begin())<=S[i])have.erase(have.begin());
}
else{
auto it=have.lb(S[i]);
while(it!=have.end()&&(*it)<=S[i]+mid)it=have.erase(it);
}
}
if(have.size())return 0;
return 1;
}
int32_t main(){
fastio
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>S[i];
S[n+1]=inf;
for(int i=1;i<=m;i++)cin>>F[i];
int l=0,r=1e9,ans=inf;
while(l<=r){
mid=l+(r-l)/2;
if(check())r=mid-1,ans=min(ans,mid);
else l=mid+1;
}
if(ans==inf)return (cout<<-1),0;
cout<<ans<<'\n';
mid=ans;
check();
for(int i=1;i<=n;i++)cout<<((di[i])?'R':'L');
}
/*
*/
컴파일 시 표준 에러 (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... |