제출 #400256

#제출 시각아이디문제언어결과실행 시간메모리
400256bigg도시들 (IOI15_towns)C++14
35 / 100
24 ms460 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 115; const int INF = 1e6; int dista[MAXN][MAXN]; pair<int, int> p1, p2; map<int, int > AB; map<int, vector<int> > AB2; int get(int a, int b){ if(dista[a][b] != -1) return dista[a][b]; dista[a][b] = dista[b][a] = getDistance(a,b); return dista[a][b]; } int disttosv[MAXN]; int pai[MAXN], peso[MAXN]; int find(int x){ if(pai[x] == x) return x; return pai[x] = find(pai[x]); } void join(int u, int v){ u = find(u), v = find(v); if(u == v) return; if(peso[u] < peso[v]) swap(u,v); pai[v] = u; peso[u] += peso[v]; } int hubDistance(int N, int sub) { p1 = {0,0}; p2 = {0,0}; AB.clear(); AB2.clear(); memset(dista, -1, sizeof(dista)); for(int i = 0; i < N; i++) pai[i] = i, peso[i] = 1; for(int i = 0; i < N; i++){ int d = get(0, i); if(d > p1.second) p1 = {i,d}; } for(int i = 0; i < N; i++){ int d = get(i, p1.first); if(d > p2.second) p2 = { i, d}; } int ans = INF; int diam = get(p1.first, p2.first); for(int i = 0; i < N; i++) ans = min(ans, (diam + abs(get(p1.first, i) - get(p2.first, i)))/2); if(sub <= 2) return ans; for(int i = 0; i < N; i++){ if(i == p1.first || i == p2.first) continue; int i1 = get(i, p1.first), i2 = get(i, p2.first); AB[i1 - (i1+i2-diam)/2]++; AB2[i1- (i1+i2-diam)/2].push_back(i); disttosv[i] = (i1+i2-diam)/2; } if(sub == 4){ int jacontei = 1; bool iscentroid = 0; for(map<int,int> :: iterator it = AB.begin(); it != AB.end(); it++){ if(it->first == ans || it->first == diam - ans){ if(jacontei <= N/2 && N - jacontei - it->second <= N/2 && it->second <= N/2) iscentroid = 1; } jacontei += it->second; } if(!iscentroid) ans = -ans; return ans; } if(sub == 3){ bool iscentroid = 0; int jacontei= 1; for(auto it : AB2){ if(it.first != ans && it.first != diam - ans){ jacontei += it.second.size(); continue; } if(jacontei <= (N/2) && N- jacontei - it.second.size() <= N/2) iscentroid = 1; for(int i = 0; i < it.second.size(); i++){ for(int j = i + 1; j < it.second.size(); j++){ if(get(it.second[i], it.second[j]) != disttosv[it.second[i]] + disttosv[it.second[j]]) join(it.second[i], it.second[j]); } } for(int i = 0; i < it.second.size(); i++) iscentroid &= (peso[find(it.second[i])] <= N/2); if(iscentroid) return ans; jacontei += it.second.size(); } if(!iscentroid) ans = -ans; } return ans; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:81:32: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   81 |     jacontei += it.second.size();
      |                                ^
towns.cpp:84:59: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |    if(jacontei <= (N/2) && N- jacontei - it.second.size() <= N/2) iscentroid = 1;
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for(int i = 0; i < it.second.size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
towns.cpp:86:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int j = i + 1; j < it.second.size(); j++){
      |                        ~~^~~~~~~~~~~~~~~~~~
towns.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |    for(int i = 0; i < it.second.size(); i++) iscentroid &= (peso[find(it.second[i])] <= N/2);
      |                   ~~^~~~~~~~~~~~~~~~~~
towns.cpp:92:31: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   92 |    jacontei += it.second.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...