답안 #1047349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047349 2024-08-07T12:04:56 Z gagik_2007 Sprinklers (CEOI24_sprinklers) C++17
3 / 100
22 ms 860 KB
#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 dp[N];
int par[N];
bool pardir[N];

int getFlowerAmount(int l, int r){
    auto it1=lower_bound(f+1,f+m+1,l);
    auto it2=upper_bound(f+1,f+m+1,r);
    int cnt=(it2-it1);
    //cout<<"GetFlowerAmount: "<<l<<" "<<r<<" - "<<cnt<<endl;
    return cnt;
}

bool check(int vl){
    //cout<<vl<<endl;
    for(int i=0;i<=n;i++){
        dp[i]=0;
        par[i]=0;
    }
    for(int i=0;i<n;i++){
        int ind=dp[i]+1;
        if(ind==m+1){
            dp[i+1]=dp[i];
            par[i+1]=i;
            pardir[i+1]=true;
            continue;
        }
        if(f[ind]>=s[i+1]&&f[ind]<=s[i+1]+vl){
            //cout<<1<<endl;
            int pos=dp[i]+getFlowerAmount(f[ind],s[i+1]+vl);
            if(pos>dp[i+1]){
                par[i+1]=i;
                pardir[i+1]=true;
            }
            dp[i+1]=max(dp[i+1],pos);
            //cout<<i+1<<" -> "<<dp[i+1]<<endl;
        }
        if(f[ind]>=s[i+1]-vl&&f[ind]<=s[i+1]){
            //cout<<2<<endl;
            int pos=dp[i]+getFlowerAmount(f[ind],s[i+1]);
            if(pos>dp[i+1]){
                par[i+1]=i;
                pardir[i+1]=false;
            }
            dp[i+1]=max(dp[i+1],pos);
            //cout<<i+1<<" -> "<<dp[i+1]<<endl;
        }
        if(i<n-1&&s[i+2]-vl<=s[i+1]&&s[i+2]<=s[i+1]+vl&&f[ind]>=s[i+2]-vl&&f[ind]<=s[i+1]+vl){
            //cout<<3<<endl;
            int pos=dp[i]+getFlowerAmount(f[ind],s[i+1]+vl);
            if(pos>dp[i+2]){
                par[i+2]=i;
            }
            dp[i+2]=max(dp[i+2],pos);
            //cout<<i+2<<" -> "<<dp[i+2]<<endl;
        }
        //cout<<i<<": "<<dp[i]<<endl;
    }
    //cout<<n<<": "<<dp[n]<<endl;
    //cout<<endl;
    if(dp[n]==m){
        return true;
    }
    return false;
}

string getAnswer(){
    string ans="";
    for(int i=0;i<n;i++){
        ans+='L';
    }
    int cur=n;
    while(cur>0){
        if(dp[cur]==0){
            break;
        }
        if(cur-par[cur]==2){
            ans[cur-1]='R';
        }
        else if(pardir[cur]){
            ans[cur-1]='R';
        }
        cur=par[cur];
    }
    return ans;
}

int binsearch(){
    int l=0,r=MOD;
    while(l<r){
        int mid=(l+r)/2;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    return l;
}

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=1;i<=n;i++){
        cin>>s[i];
    }
    for(int i=1;i<=m;i++){
        cin>>f[i];
    }
    int res=binsearch();
    if(res==MOD){
        cout<<-1<<endl;
        return 0;
    }
    check(res);
    string ans=getAnswer();
    cout<<res<<endl<<ans<<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 4 ms 688 KB Correct
3 Correct 0 ms 344 KB Correct
4 Correct 5 ms 860 KB Correct
5 Correct 5 ms 860 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 380 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 6 ms 860 KB User solution is worse than jury's solution
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Incorrect 1 ms 344 KB User solution is incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Incorrect 22 ms 860 KB User solution is worse than jury's solution
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 4 ms 688 KB Correct
4 Correct 0 ms 344 KB Correct
5 Correct 5 ms 860 KB Correct
6 Correct 5 ms 860 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 1 ms 380 KB Correct
10 Correct 0 ms 348 KB Correct
11 Incorrect 6 ms 860 KB User solution is worse than jury's solution
12 Halted 0 ms 0 KB -