# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1036627 |
2024-07-27T15:00:58 Z |
vjudge1 |
Towns (IOI15_towns) |
C++17 |
|
43 ms |
28240 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()){
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:21:28: warning: unused parameter 'sub' [-Wunused-parameter]
21 | int hubDistance(int N, int sub) {
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
27996 KB |
Output is correct |
2 |
Correct |
25 ms |
27740 KB |
Output is correct |
3 |
Correct |
5 ms |
27464 KB |
Output is correct |
4 |
Correct |
28 ms |
27952 KB |
Output is correct |
5 |
Correct |
28 ms |
27996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
27992 KB |
Output is correct |
2 |
Correct |
33 ms |
27740 KB |
Output is correct |
3 |
Correct |
28 ms |
27996 KB |
Output is correct |
4 |
Correct |
27 ms |
27992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
27740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
28240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
27736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
27740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |