Submission #294453

#TimeUsernameProblemLanguageResultExecution timeMemory
294453b00n0rpTowns (IOI15_towns)C++17
61 / 100
25 ms1280 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i = 0; i < n; i ++) #define FOR(i,a,b) for(int i = a; i < b; i ++) #define vi vector<int> #define pb push_back #define F first #define S second int d0[1005],dA[1005]; int n,A,B; int dist[1005][1005]; int quer = 0; int getD(int i,int j){ if(dist[i][j] == -1){ quer++; dist[i][j] = getDistance(i,j); dist[j][i] = dist[i][j]; } return dist[i][j]; } int hubDistance(int N, int sub){ quer = 0; n = N; REP(i,n){ dist[i][i] = 0; FOR(j,i+1,n){ dist[i][j] = -1; dist[j][i] = -1; } } A = B = 0; d0[0] = 0; FOR(i,1,n){ d0[i] = getD(0,i); if(d0[i] > d0[A]) A = i; } dA[0] = d0[A]; dA[A] = 0; FOR(i,1,n){ if(i == A) continue; dA[i] = getD(A,i); if(dA[i] > dA[B]) B = i; } int R = 1000000000; map<int,int> gg; // dist from A from path A-0 REP(i,n){ int lol = (dA[0]+dA[i]-d0[i])/2; gg[lol]++; R = min(R,max(dA[B]-lol,lol)); } if(sub <= 2) return R; int cur = 0; int hub = -1; for(auto x:gg){ if(cur > n/2) break; if(max(dA[B]-x.F,x.F) != R){ cur += x.S; continue; } int p1 = x.S,p2 = n-cur-x.S; cur += p1; if(p2 > n/2) continue; if(p1 <= n/2) return R; hub = x.F; } if(hub == -1 or sub == 4) return -R; vi elig; REP(i,n){ if((dA[0]+dA[i]-d0[i])/2 == hub) elig.pb(i); } REP(bruh,100){ int i = rand()%(elig.size()); int cnt = 0; int left = elig.size(); for(auto x:elig){ cnt += (quer < 5*n and getD(elig[i],x) != (dA[x]+dA[elig[i]]-2*hub)); left--; if(cnt > n/2) return -R; if(cnt+left < n/2) break; } if(cnt > n/2) return -R; } return R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:79:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   79 |   int i = rand()%(elig.size());
      |           ~~~~~~^~~~~~~~~~~~~~
towns.cpp:81:23: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   81 |   int left = elig.size();
      |              ~~~~~~~~~^~
#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...