# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1036682 |
2024-07-27T15:27:10 Z |
vjudge1 |
Towns (IOI15_towns) |
C++17 |
|
65 ms |
25428 KB |
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
int n;
int dist[200][200];
const int lim=1e6+100;
int pref[lim],suf[lim];
vector<int>blw[lim];
int query(int i,int j){
if(j<i)swap(i,j);
if(!dist[i][j])dist[i][j]=getDistance(i,j);
return dist[i][j];
}
int hubDistance(int N, int sub) {
for(int i=0;i<=1000000;i++)blw[i].clear();
memset(dist,0,sizeof(dist));
n=N;
int past=-1,point1=-1;
for(int i=1;i<n;i++){
if(past<query(0,i)){
point1=i;
past=query(0,i);
}
}
past=-1;
int point2=-1;
for(int i=0;i<n;i++){
if(i==point1)continue;
if(past<query(point1,i)){
point2=i;
past=query(point1,i);
}
}
int ds=query(point1,point2);
int ans=1e9;
for(int i=0;i<n;i++){
if(i==point1||i==point2)continue;
int tem=(query(point1,i)+query(point2,i)-ds)/2;
int val1=query(point1,i)-tem;
int val2=query(point2,i)-tem;
//cerr<<val1<<" "<<val2<<" ?\n";
blw[val1].push_back(i);
ans=min(ans,max({tem,val1,val2}));
}
int dude1=ans,dude2=ds-ans;
ans=-ans;
pref[0]=1;
suf[ds]=1;
for(int i=1;i<=ds;i++){
pref[i]=pref[i-1]+blw[i].size();
suf[ds-i]=suf[ds-i+1]+blw[ds-i].size();
}
for(int dude:{dude1,dude2}){
if(!blw[dude].size())continue;
if(n/2<pref[dude-1]||n/2<suf[dude+1])continue;
if(n/2<blw[dude].size()){
if(sub!=3)continue;
bool nope=0;
for(int i=0;i<blw[dude].size();i++){
int cnt=1;
int tem1=(query(point1,blw[dude][i])+query(point2,blw[dude][i])-ds)/2;
for(int j=0;j<blw[dude].size();j++){
if(i==j)continue;
int tem2=(query(point1,blw[dude][j])+query(point2,blw[dude][j])-ds)/2;
if(tem1+tem2!=query(blw[dude][j],blw[dude][i]))cnt++;
}
if(n/2<cnt){
nope=1;
break;
}
}
if(nope)continue;
}
ans=abs(ans);
}
return ans;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:57:20: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
57 | pref[i]=pref[i-1]+blw[i].size();
| ~~~~~~~~~^~~~~~~~~~~~~~
towns.cpp:58:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
58 | suf[ds-i]=suf[ds-i+1]+blw[ds-i].size();
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
towns.cpp:63:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | if(n/2<blw[dude].size()){
| ~~~^~~~~~~~~~~~~~~~~
towns.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<blw[dude].size();i++){
| ~^~~~~~~~~~~~~~~~~
towns.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int j=0;j<blw[dude].size();j++){
| ~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
24716 KB |
Output is correct |
2 |
Correct |
34 ms |
24376 KB |
Output is correct |
3 |
Correct |
13 ms |
23900 KB |
Output is correct |
4 |
Correct |
61 ms |
24644 KB |
Output is correct |
5 |
Correct |
39 ms |
24668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
24664 KB |
Output is correct |
2 |
Correct |
36 ms |
24504 KB |
Output is correct |
3 |
Correct |
65 ms |
24520 KB |
Output is correct |
4 |
Correct |
39 ms |
24668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
24592 KB |
Output is correct |
2 |
Correct |
41 ms |
24668 KB |
Output is correct |
3 |
Correct |
11 ms |
23896 KB |
Output is correct |
4 |
Correct |
38 ms |
24520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
25428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
24452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
24400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |