# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025550 |
2024-07-17T06:48:52 Z |
vjudge1 |
Towns (IOI15_towns) |
C++17 |
|
13 ms |
1148 KB |
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
int Ddis[201][201];
inline int getD(int a,int b){
if(a==b)return 0;
if(a>b)swap(a,b);
if(Ddis[a][b])
return Ddis[a][b];
return Ddis[a][b]=getDistance(a,b);
}
pair<int,int> mnn[200];
bool samesub(int a,int b){
auto[i1,d1]=mnn[a];
auto[i2,d2]=mnn[b];
return getD(i1,i2)<d1+d2;
}
map<int,int>mp2;
int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){
mp2.clear();
int toleft=0,toright=0,tot=0;
vector<pair<int,int>> Tis;
for(auto [i,x]:mp){tot+=x.size();
if(i<pivot) toleft+=x.size();
else if(i==pivot) Tis=x;
else toright+=x.size();}
for(auto[i,k]:Tis)
mnn[i]={i,k};
if(toleft>tot/2||toright>tot/2)
return 0;
if(Tis.size()<=tot/2)
return 1;
int cnt=0,bk=0;
for(auto [i,K]:Tis){
if(!cnt){
mp2[i]=1;
bk=i;
cnt=i;
} else {
if(samesub(bk,i)){
mp2[bk]++;
cnt++;
} else {
cnt--;
mp2[i]=1;
}
}
}
int asthis=0;
for(auto[kk,kkk]:mp2)
if(samesub(bk,kk))
asthis+=samesub(kk,bk)*kkk;
return asthis<=tot/2;
}
int hubDistance(int N, int sub) {
memset(Ddis,0,sizeof Ddis);
int pivot=0;
int farnod=pivot,fardis=0;
for(int i=0;i<N;i++)
if(getD(i,pivot)>fardis)
farnod=i,fardis=getD(i,pivot);
fardis=0;
int X=farnod;
for(int i=0;i<N;i++)
if(getD(i,X)>fardis)
farnod=i,fardis=getD(i,X);
int Y=farnod,K=fardis;
map<int,vector<pair<int,int>>> mp;
for(int i=0;i<N;i++){
int toX=getD(X,i),toY=getD(pivot,i);
int dep=(toX+toY-getD(pivot,X))/2;
int distofP=getD(pivot,X)+toX-toY;
mp[distofP].push_back({i,dep});
}
int candidate2=mp.lower_bound(K)->first,candidate1=(--mp.lower_bound(K))->first;
int R;
if(K-candidate1<candidate2-K){
R=K-candidate1/2;
if(!ok(mp,candidate1,sub&1))
R=-R;
} else if(K-candidate1>candidate2-K){
R=candidate2/2;
if(!ok(mp,candidate2,sub&1))
R=-R;
} else {
R=candidate2/2;
if(!ok(mp,candidate1,sub&1)&&
!ok(mp,candidate2,sub&1))
R=-R;
}
return R;
}
Compilation message
towns.cpp: In function 'int ok(std::map<int, std::vector<std::pair<int, int> > >, int, int)':
towns.cpp:23:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
23 | for(auto [i,x]:mp){tot+=x.size();
| ^
towns.cpp:24:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
24 | if(i<pivot) toleft+=x.size();
| ^
towns.cpp:26:30: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
26 | else toright+=x.size();}
| ^
towns.cpp:31:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
31 | if(Tis.size()<=tot/2)
| ~~~~~~~~~~^~~~~~~
towns.cpp:19:55: warning: unused parameter 'sub' [-Wunused-parameter]
19 | int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){
| ~~~~^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:67:9: warning: unused variable 'Y' [-Wunused-variable]
67 | int Y=farnod,K=fardis;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
12 ms |
648 KB |
Output is correct |
5 |
Correct |
10 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
604 KB |
Output is correct |
4 |
Correct |
10 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
672 KB |
Output is correct |
2 |
Correct |
10 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
10 ms |
1100 KB |
Output is correct |
3 |
Correct |
10 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
604 KB |
Output is correct |
2 |
Correct |
9 ms |
1116 KB |
Output is correct |
3 |
Correct |
10 ms |
1148 KB |
Output is correct |