Submission #779283

# Submission time Handle Problem Language Result Execution time Memory
779283 2023-07-11T09:51:48 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
39 ms 10448 KB
//#include<bits/stdc++.h>
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define N 100005
bitset<N>  var;
int main(){
	lalala;
	int n,m;cin>>n>>m;

	int sa[n],sol[m];
	for(int i=0;i<n;i++)cin>>sa[i];
	for(int i=0;i<m;i++)cin>>sol[i];
	sort(sa,sa+n);
	sort(sol,sol+m);
	if(n==m){
		int mx=0;
		for(int i=0;i<n;i++)mx=max(mx,abs(sa[i]-sol[i]));
		cout<<mx<<endl;
		return 0;
	}

	if(n<m){
		int mx=0;
		vector<int> kimler[N],best;
		for(int i=0;i<n;i++){
			int l=0,r=m-1;
			while(l<r){
				int mid=(l+r)/2;
				if(sol[mid]>=sa[i]){
					r=mid;
				}
				else l=mid+1;
			}
			int a=l,b=l;
			if(l!=0)a--;
			//cout<<a<<" "<<b<<endl;
			if(abs(sol[b]-sa[i])<abs(sol[a]-sa[i])){
				best.pb(b);
				kimler[b].pb(i);
			}
			else {
				best.pb(a);
				kimler[a].pb(i);
			}
		}
		for(auto u:best){
			if(kimler[u].size()==1&&var[u]==0){
				mx=max(mx,abs(sa[kimler[u][0]]-sol[u]));
				var[u]=1;
				continue;
			}
			int a=kimler[u][0], b=kimler[u][1];
			int mx1=0,mx2=0;
			if(u!=0){
				mx1=max(abs(sa[a]-sol[u-1]),abs(sa[b]-sol[u]));
			}
			if(u!=m-1){
				mx2=max(abs(sa[a]-sol[u]),abs(sa[b]-sol[u+1])) ;
			}

				var[u]=1;
			if(mx1>mx2&&mx2!=0){
				var[u+1]=1;
			}
			else var[u-1]=1;
			mx=max(mx,max(mx1,mx2));
		}
		cout<<mx<<endl;

	}
	else{
		int mx=0;
		vector<int> kimler[N],best;
		for(int i=0;i<m;i++){
			int l=0,r=n-1;
			while(l<r){
				int mid=(l+r)/2;
				if(sa[mid]>=sol[i]){
					r=mid;
				}
				else l=mid+1;
			}
			int a=l,b=l;
			if(l!=0)a--;
			//cout<<a<<" "<<b<<endl;
			if(abs(sa[b]-sol[i])<abs(sa[a]-sol[i])){
				best.pb(b);
				kimler[b].pb(i);
			}
			else {
				best.pb(a);
				kimler[a].pb(i);
			}
		}
		for(auto u:best){
			if(kimler[u].size()==1&&var[u]==0){
				mx=max(mx,abs(sol[kimler[u][0]]-sa[u]));
				var[u]=1;
				continue;
			}
			int a=kimler[u][0], b=kimler[u][1];
			int mx1=0,mx2=0;
			if(u!=0){
				mx1=max(abs(sol[a]-sa[u-1]),abs(sol[b]-sa[u]));
			}
			if(u!=n-1){
				mx2=max(abs(sol[a]-sa[u]),abs(sol[b]-sa[u+1]));
			}

			var[u]=1;
			if(mx1>mx2&&mx2!=0){
				var[u+1]=1;
			}
			else var[u-1]=1;
			mx=max(mx,max(mx1,mx2));
		}
		cout<<mx<<endl;

	}
}


# Verdict Execution time Memory Grader output
1 Correct 16 ms 3412 KB Output is correct
2 Correct 29 ms 3452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3412 KB Output is correct
2 Correct 31 ms 3432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Runtime error 5 ms 5460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Runtime error 5 ms 5460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5420 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 9672 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 10448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 9672 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -