제출 #400252

#제출 시각아이디문제언어결과실행 시간메모리
400252peuch도시들 (IOI15_towns)C++17
35 / 100
26 ms1852 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 310; int dist[MAXN][MAXN]; int marc[MAXN][MAXN]; int p1, p2, n; 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; cnt++; return dist[i][j] = dist[j][i] = getDistance(i, j); } int getSize(vector<int> values, int goal){ vector<multiset<int> > alive, dead; for(int i = 0; i < values.size(); i++){ multiset<int> aux; aux.insert(values[i]); alive.push_back(aux); } while(alive.size() > 1){ vector<multiset<int> > aux; for(int i = 0; i + 1 < alive.size(); i += 2){ multiset<int> g1, g2; g1 = alive[i]; g2 = alive[i + 1]; int v1 = *g1.begin(), v2 = *g2.begin(); int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2; if(x != goal){ while(!g2.empty()){ g1.insert(*g2.begin()); g2.erase(g2.begin()); } aux.push_back(g1); } else{ dead.push_back(g1); dead.push_back(g2); } } if(alive.size() % 2 == 1) aux.push_back(alive.back()); alive = aux; } if(alive.empty()) return 1; for(int i = 0; i < dead.size(); i++){ multiset<int> g1, g2; g1 = alive[0]; g2 = dead[i]; int v1 = *g1.begin(), v2 = *g2.begin(); int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2; if(x != goal){ while(!g2.empty()){ g1.insert(*g2.begin()); g2.erase(g2.begin()); } alive[0] = g1; } } return (alive[0].size() > n / 2) ? -1 : 1; } int hubDistance(int N, int sub) { srand(time(0)); n = N; p1 = 0, p2 = 0; int maxi = 0; cnt = 0; memset(dist, 0, sizeof(dist)); memset(marc, 0, sizeof(marc)); 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(lSize > N / 2 || rSize > N / 2) return -ans; else if(lMid.size() > N / 2) return getSize(lMid, min(ans, diam - ans)) * ans; else if(rMid.size() > N / 2) return getSize(rMid, max(ans, diam - ans)) * ans; return ans; }

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

towns.cpp: In function 'int getSize(std::vector<int>, int)':
towns.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 0; i < values.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
towns.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::multiset<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int i = 0; i + 1 < alive.size(); i += 2){
      |                  ~~~~~~^~~~~~~~~~~~~~
towns.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::multiset<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0; i < dead.size(); i++){
      |                 ~~^~~~~~~~~~~~~
towns.cpp:65:26: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |  return (alive[0].size() > n / 2) ? -1 : 1;
      |          ~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:69:12: warning: conversion from 'time_t' {aka 'long int'} to 'unsigned int' may change value [-Wconversion]
   69 |  srand(time(0));
      |        ~~~~^~~
towns.cpp:105:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  105 |  else if(lMid.size() > N / 2)
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:107:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |  else if(rMid.size() > N / 2)
      |          ~~~~~~~~~~~~^~~~~~~
#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...