답안 #1030250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030250 2024-07-22T00:41:50 Z 12345678 도시들 (IOI15_towns) C++17
25 / 100
10 ms 1016 KB
#include "towns.h"
#include <bits/stdc++.h>

using namespace std;

int hubDistance(int N, int sub) {
	pair<int, int> mx={0, 0};
	int l=0, r, mn=INT_MAX;
	vector<int> dl(N), dr(N);
	for (int i=1; i<N;i ++) dl[i]=getDistance(0, i), mx=max(mx, {dl[i], i});
	r=mx.second;
	dr[l]=dl[r];
	for (int i=0; i<N;i ++) if (i!=l&&i!=r) dr[i]=getDistance(r, i);
	int dist=dl[r];
	map<int, int> mp;
	map<int, vector<int>> mpd;
	for (int i=0; i<N; i++)
	{
		int x=dl[i], y=dr[i], h=(x+dist-y)/2, dh=(x+y-dist)/2;
		if (mp.find(h)==mp.end()) mp[h]=dh;
		else mp[h]=max(mp[h], dh);
		mpd[h].push_back(i);
	}	
	for (auto [x, a]:mp)
	{
		int mx=a;
		for (auto [y, b]:mp) mx=max(mx, abs(x-y)+b);
		mn=min(mn, mx); 
	}
	int sz=0, can=-1;
	for (auto [x, a]:mp)
	{
		int mx=a;
		for (auto [y, b]:mp) mx=max(mx, abs(x-y)+b);
		if (mn==mx) if (sz<=(N/2)&&(mpd.size()-1)<=(N/2)&&(N-sz-mpd.size())<=(N/2)) can=1;
		sz+=mpd[x].size();
	}
	return mn*-1;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:26:7: warning: declaration of 'mx' shadows a previous local [-Wshadow]
   26 |   int mx=a;
      |       ^~
towns.cpp:7:17: note: shadowed declaration is here
    7 |  pair<int, int> mx={0, 0};
      |                 ^~
towns.cpp:33:7: warning: declaration of 'mx' shadows a previous local [-Wshadow]
   33 |   int mx=a;
      |       ^~
towns.cpp:7:17: note: shadowed declaration is here
    7 |  pair<int, int> mx={0, 0};
      |                 ^~
towns.cpp:35:44: warning: comparison of integer expressions of different signedness: 'std::map<int, std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |   if (mn==mx) if (sz<=(N/2)&&(mpd.size()-1)<=(N/2)&&(N-sz-mpd.size())<=(N/2)) can=1;
      |                              ~~~~~~~~~~~~~~^~~~~~~
towns.cpp:35:70: warning: comparison of integer expressions of different signedness: 'std::map<int, std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |   if (mn==mx) if (sz<=(N/2)&&(mpd.size()-1)<=(N/2)&&(N-sz-mpd.size())<=(N/2)) can=1;
      |                                                     ~~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp:36:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   36 |   sz+=mpd[x].size();
      |                   ^
towns.cpp:30:12: warning: variable 'can' set but not used [-Wunused-but-set-variable]
   30 |  int sz=0, can=-1;
      |            ^~~
towns.cpp:6:28: warning: unused parameter 'sub' [-Wunused-parameter]
    6 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 856 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 10 ms 1016 KB Output is correct
5 Correct 10 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 348 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 10 ms 860 KB Output is correct
4 Correct 9 ms 984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -