제출 #400239

#제출 시각아이디문제언어결과실행 시간메모리
400239bigg도시들 (IOI15_towns)C++11
컴파일 에러
0 ms0 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 1e9; int dist[5][MAXN]; pair<int, int> p1, p2; map<int, int> AB; int hubDistance(int N, int sub) { p1 = {0,0}; p2 = {0,0}; AB.clear(); for(int i = 0; i < N; i++){ int d = getDistance(0, i); if(d > p1.second) p1 = {i,d}; } for(int i = 0; i < N; i++){ dist[0][i] = getDistance(i, p1.first); if(dist[0][i] > p2.second) p2 = { i, dist[0][i]}; } for(int i = 0; i < N; i++){ dist[1][i] = getDistance(i, p2.first); } int ans = MAXN; int diam = dist[0][p2.first]; for(int i = 0; i < N; i++) ans = min(ans, (diam + abs(dist[0][i] - dist[1][i]))/2); for(int i = 0; i < N; i++){ if(i == p1.first || i == p2.first) continue; int i1 = dist[0][i], i2 = dist[1][i]; AB[i1 - (i1+i2-diam)/2]++; } int jacontei = 1; bool iscentroid = 0; for(map<int,int> :: iterator it : AB){ 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; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:38:36: error: conversion from 'std::pair<const int, int>' to non-scalar type 'std::map<int, int>::iterator' {aka 'std::_Rb_tree_iterator<std::pair<const int, int> >'} requested
   38 |  for(map<int,int> :: iterator it : AB){
      |                                    ^~
towns.cpp:39:9: error: 'std::map<int, int>::iterator' {aka 'struct std::_Rb_tree_iterator<std::pair<const int, int> >'} has no member named 'first'
   39 |   if(it.first == ans || it.first == diam - ans){
      |         ^~~~~
towns.cpp:39:28: error: 'std::map<int, int>::iterator' {aka 'struct std::_Rb_tree_iterator<std::pair<const int, int> >'} has no member named 'first'
   39 |   if(it.first == ans || it.first == diam - ans){
      |                            ^~~~~
towns.cpp:40:44: error: 'std::map<int, int>::iterator' {aka 'struct std::_Rb_tree_iterator<std::pair<const int, int> >'} has no member named 'second'
   40 |    if(jacontei <= N/2 && N - jacontei - it.second <= N/2 && it.second <= N/2) iscentroid = 1;
      |                                            ^~~~~~
towns.cpp:40:64: error: 'std::map<int, int>::iterator' {aka 'struct std::_Rb_tree_iterator<std::pair<const int, int> >'} has no member named 'second'
   40 |    if(jacontei <= N/2 && N - jacontei - it.second <= N/2 && it.second <= N/2) iscentroid = 1;
      |                                                                ^~~~~~
towns.cpp:42:18: error: 'std::map<int, int>::iterator' {aka 'struct std::_Rb_tree_iterator<std::pair<const int, int> >'} has no member named 'second'
   42 |   jacontei += it.second;
      |                  ^~~~~~
towns.cpp:10:28: warning: unused parameter 'sub' [-Wunused-parameter]
   10 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~