# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779282 |
2023-07-11T09:49:56 Z |
vjudge1 |
Cipele (COCI18_cipele) |
C++17 |
|
36 ms |
5684 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])) ;
}
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]));
}
mx=max(mx,max(mx1,mx2));
}
cout<<mx<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3788 KB |
Output is correct |
2 |
Correct |
33 ms |
4264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
4004 KB |
Output is correct |
2 |
Correct |
30 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
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 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
5492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
5684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
5464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |