Submission #1109670

#TimeUsernameProblemLanguageResultExecution timeMemory
1109670PioneerSprinklers (CEOI24_sprinklers)C++17
0 / 100
9 ms3532 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define ll long long // #define int ll #define all(v) v.begin(),v.end() #define sz(s) ((int)s.size()) #define pb push_back #define F first #define S second #define pii pair<int,int> #define ppb pop_back #define lb lower_bound #define ub upper_bound using namespace std; const ll inf=1e18; const int MAX=1e5+10; const int MX=1e8; const int mod=1e9+7; int binpow(int a,int n){ if(!n)return 1; if(n%2==1)return a*binpow(a,n-1)%mod; int k=binpow(a,n/2); return k*k%mod; } int n,m; int s[MAX],f[MAX]; int dp[MAX][3]; int pr[MAX][3]; vector<int> vf; bool check(int mid){ memset(dp,-1,sizeof(dp)); memset(pr,-1,sizeof(pr)); for(int i=1;i<=n;i++){ for(int j=0;j<3;j++){ int k=i-1; if(ub(all(vf),dp[k][j])==vf.end()||vf[ub(all(vf),dp[k][j])-vf.begin()]>=s[i]){ if(max(dp[k][j],s[i]+mid)>dp[i][0]){ pr[i][0]=j; dp[i][0]=max(dp[k][j],s[i]+mid); } } if(ub(all(vf),dp[k][j])==vf.end()||vf[ub(all(vf),dp[k][j])-vf.begin()]>=s[i]-mid){ if(max(dp[k][j],s[i])>dp[i][2]){ pr[i][2]=j; dp[i][2]=max(dp[k][j],s[i]); } } k--; if(k<0)continue; if(s[i]-s[i-1]>mid){ if(ub(all(vf),dp[k][j])==vf.end()||vf[ub(all(vf),dp[k][j])-vf.begin()]>=s[i-1]){ if(ub(all(vf),max(dp[k][j],s[i-1]+mid))==vf.end()||vf[ub(all(vf),max(dp[k][j],s[i-1]+mid))-vf.begin()]>=s[i]-mid){ if(max(dp[k][j],s[i])>dp[i][1]){ pr[i][1]=j; dp[i][1]=max(dp[k][j],s[i]); } } } } else{ if(ub(all(vf),dp[k][j])==vf.end()||vf[ub(all(vf),dp[k][j])-vf.begin()]>=s[i]-mid){ if(max(dp[k][j],s[i-1]+mid)>dp[i][1]){ pr[i][1]=j; dp[i][1]=max(dp[k][j],s[i-1]+mid); } } } } // for(int j=0;j<4;j++){ // if(dp[i][j]!=-1)cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n"; // } } for(int j=0;j<3;j++){ // cout<<dp[n][j]<<"\n"; if(dp[n][j]>=f[m])return 1; } return 0; } void solve(){ cin>>n>>m; for(int i=1;i<=n;i++)cin>>s[i]; for(int i=1;i<=m;i++){ cin>>f[i]; vf.pb(f[i]); } int l=0,r=1e9,res=-1; while(l<=r){ int m=(l+r)/2; if(check(m)){ r=m-1; res=m; } else l=m+1; } cout<<res<<"\n"; if(res!=-1){ check(res); int a=n,b=-1; string s; for(int k=0;k<3;k++)if(dp[n][k]>=f[n]){ b=k; break; } while(a>0){ if(b==0){ b=pr[a][b]; a--; s.pb('R'); } else if(b==1){ b=pr[a][b]; a-=2; s.pb('L'); s.pb('R'); } else if(b==2){ b=pr[a][b]; a-=2; s.pb('L'); s.pb('L'); } else{ b=pr[a][b]; a--; s.pb('L'); } } reverse(all(s)); cout<<s<<"\n"; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--)solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:131:26: warning: array subscript [0, 2] is outside array bounds of 'int [3]' [-Warray-bounds]
  131 |                 b=pr[a][b];
      |                   ~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...