Submission #1036682

#TimeUsernameProblemLanguageResultExecution timeMemory
1036682vjudge1Towns (IOI15_towns)C++17
48 / 100
65 ms25428 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...