Submission #1025374

#TimeUsernameProblemLanguageResultExecution timeMemory
1025374vjudge1Towns (IOI15_towns)C++17
0 / 100
10 ms1112 KiB
#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); } mt19937 rng(random_device{}()); bool samesub(pair<int,int>a,pair<int,int>b){ auto[i1,d1]=a; auto[i2,d2]=b; return getD(i1,i2)<d1+d2; } int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){ 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();} if(toleft>tot/2||toright>tot/2) return 0; if(Tis.size()<=tot/2) return 1; if(!sub) return 0; vector<pair<int,pair<int,int>>> STUF; for(auto i:Tis){ int has=0; for(auto&[q,w]:STUF) if(samesub(i,w)) has=1,q++; if(!has)STUF.push_back({1,i}); } for(auto[s,k]:STUF) if(s>tot/2) return 0; return 1; } int hubDistance(int N, int sub) { int pivot=rng()%N; 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; mp[0].push_back({X,0}),mp[2*K].push_back({Y,0}); for(int i=0;i<N;i++){ if(i==X||i==Y)continue; int toX=getD(X,i),toY=getD(Y,i); int dep=(toX+toY-K)/2; int distofP=K+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 (stderr)

towns.cpp: In function 'int ok(std::map<int, std::vector<std::pair<int, int> > >, int, int)':
towns.cpp:21:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   21 |     for(auto [i,x]:mp){tot+=x.size();
      |                                    ^
towns.cpp:22:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   22 |         if(i<pivot) toleft+=x.size();
      |                                    ^
towns.cpp:24:30: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   24 |         else toright+=x.size();}
      |                              ^
towns.cpp:27: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]
   27 |     if(Tis.size()<=tot/2)
      |        ~~~~~~~~~~^~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:44:20: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   44 |     int pivot=rng()%N;
      |               ~~~~~^~
#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...