제출 #399941

#제출 시각아이디문제언어결과실행 시간메모리
399941peuchTowns (IOI15_towns)C++17
61 / 100
28 ms1104 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 310; int dist[MAXN][MAXN]; int marc[MAXN][MAXN]; int cnt; int getD(int i, int j){ if(marc[i][j]) return dist[i][j]; marc[i][j] = marc[j][i] = 1; if(i == j) return dist[i][j] = dist[j][i] = 0; // printf("Asking: %d %d\n", i, j); cnt++; return dist[i][j] = dist[j][i] = getDistance(i, j); } int hubDistance(int N, int sub) { int p1 = 0, p2 = 0; int maxi = 0; memset(dist, 0, sizeof(dist)); memset(marc, 0, sizeof(marc)); cnt = 0; for(int i = 0; i < N; i++){ int aux = getD(0, i); if(aux > maxi) p1 = i, maxi = aux; } maxi = 0; for(int i = 0; i < N; i++) if(getD(p1, i) > maxi) maxi = getD(p1, i), p2 = i; int diam = getD(p1, p2); int cruz0 = (diam + getD(p1, 0) - getD(p2, 0)) / 2; int ans = max(cruz0, diam - cruz0); for(int i = 0; i < N; i++){ int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2; ans = min(ans, max(x, diam - x)); } if(sub <= 2) return ans; int lSize = 0, rSize = 0; vector<int> lMid, rMid; for(int i = 0; i < N; i++){ int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2; if(x < min(ans, diam - ans)) lSize++; else if(x == min(ans, diam - ans)) lMid.push_back(i); else if(x == max(ans, diam - ans)) rMid.push_back(i); else rSize++; } if(sub == 4){ if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans; return ans; } if(lSize > N / 2 || rSize > N / 2) return -ans; else if(lMid.size() > N / 2){ stack<int> pilha; for(int i = 0; i < lMid.size(); i++){ if(pilha.empty()) pilha.push(lMid[i]); else{ int aux = getD(p1, pilha.top()); int x = (aux + getD(p1, lMid[i]) - getD(pilha.top(), lMid[i])) / 2; if(x == min(ans, diam - ans)) pilha.pop(); else pilha.push(lMid[i]); } } if(pilha.empty()) return ans; int k = pilha.top(); vector<int> grp; grp.push_back(k); int cnt1 = 1, cnt2 = 0; for(int i = lMid.size() - 1; i >= 0; i--){ if(lMid[i] == k) continue; int x; bool flag = true; for(int j = 0; j < grp.size(); j++){ if(!marc[grp[j]][lMid[i]]) continue; x = (getD(p1, grp[j]) + getD(p1, lMid[i]) - getD(grp[j], lMid[i])) / 2; flag = false; break; } if(flag) x = (getD(p1, k) + getD(p1, lMid[i]) - getD(k, lMid[i])) / 2; if(x > min(ans, diam - ans)) cnt1++, grp.push_back(lMid[i]); else cnt2++; if(cnt1 > N / 2 || cnt2 > N / 2) break; } if(cnt1 > N / 2) return -ans; return ans; } else if(rMid.size() > N / 2){ stack<int> pilha; for(int i = 0; i < rMid.size(); i++){ if(pilha.empty()) pilha.push(rMid[i]); else{ int aux = getD(p1, pilha.top()); int x = (aux + getD(p1, rMid[i]) - getD(pilha.top(), rMid[i])) / 2; if(x == max(ans, diam - ans)) pilha.pop(); else pilha.push(rMid[i]); } } if(pilha.empty()) return ans; int k = pilha.top(); vector<int> grp; grp.push_back(k); int cnt1 = 1, cnt2 = 0; for(int i = rMid.size() - 1; i >= 0; i--){ if(rMid[i] == k) continue; int x; bool flag = true; for(int j = 0; j < grp.size(); j++){ if(!marc[grp[j]][rMid[i]]) continue; x = (getD(p1, grp[j]) + getD(p1, rMid[i]) - getD(grp[j], rMid[i])) / 2; flag = false; break; } if(flag) x = (getD(p1, k) + getD(p1, rMid[i]) - getD(k, rMid[i])) / 2; if(x > max(ans, diam - ans)) cnt1++, grp.push_back(rMid[i]); else cnt2++; if(cnt1 > N / 2 || cnt2 > N / 2) break; } if(cnt1 > N / 2) return -ans; return ans; } return ans; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:54:52: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                        ~~~~~~~~~~~~^~~~~~~
towns.cpp:54:75: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                                               ~~~~~~~~~~~~^~~~~~~
towns.cpp:59:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |  else if(lMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int i = 0; i < lMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:75:27: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   75 |   for(int i = lMid.size() - 1; i >= 0; i--){
      |               ~~~~~~~~~~~~^~~
towns.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |    for(int j = 0; j < grp.size(); j++){
      |                   ~~^~~~~~~~~~~~
towns.cpp:93:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   93 |  else if(rMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:95:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |   for(int i = 0; i < rMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:109:27: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  109 |   for(int i = rMid.size() - 1; i >= 0; i--){
      |               ~~~~~~~~~~~~^~~
towns.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |    for(int j = 0; j < grp.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...