제출 #1026326

#제출 시각아이디문제언어결과실행 시간메모리
1026326boyliguanhan도시들 (IOI15_towns)C++17
100 / 100
15 ms1248 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); } pair<int,int> mnn[200]; bool samesub(int a,int b){ auto[i1,d1]=mnn[a]; auto[i2,d2]=mnn[b]; return getD(i1,i2)<d1+d2; } map<int,int>mp2; int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){ mp2.clear(); 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();} for(auto[i,k]:Tis) mnn[i]={i,k}; if(toleft>tot/2||toright>tot/2) return 0; if(Tis.size()<=tot/2) return 1; int cnt=0,bk=0; for(auto [i,K]:Tis){ if(!cnt){ mp2[i]=1; bk=i; cnt=i; } else { if(samesub(bk,i)){ mp2[bk]++; cnt++; } else { cnt--; mp2[i]=1; } } } int asthis=0; for(auto[kk,kkk]:mp2) if(samesub(bk,kk)) asthis+=samesub(kk,bk)*kkk; return asthis<=tot/2; } int hubDistance(int N, int sub) { memset(Ddis,0,sizeof Ddis); int pivot=0; 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; for(int i=0;i<N;i++){ int toX=getD(X,i),toY=getD(pivot,i); int dep=(toX+toY-getD(pivot,X))/2; int distofP=getD(pivot,X)+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; }

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int ok(std::map<int, std::vector<std::pair<int, int> > >, int, int)':
towns.cpp:23:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   23 |     for(auto [i,x]:mp){tot+=x.size();
      |                                    ^
towns.cpp:24:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   24 |         if(i<pivot) toleft+=x.size();
      |                                    ^
towns.cpp:26:30: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   26 |         else toright+=x.size();}
      |                              ^
towns.cpp:31: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]
   31 |     if(Tis.size()<=tot/2)
      |        ~~~~~~~~~~^~~~~~~
towns.cpp:19:55: warning: unused parameter 'sub' [-Wunused-parameter]
   19 | int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){
      |                                                   ~~~~^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:67:9: warning: unused variable 'Y' [-Wunused-variable]
   67 |     int Y=farnod,K=fardis;
      |         ^
#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...