제출 #411299

#제출 시각아이디문제언어결과실행 시간메모리
411299ja_kingy도시들 (IOI15_towns)C++14
49 / 100
24 ms964 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; int hubDistance(int n, int sub) { vector<int> d0(n), d1(n); int mx = 0, R = 1e9; for (int i = 1; i < n; ++i) { d0[i] = getDistance(0, i); if (d0[i] > d0[mx]) mx = i; } d1[0] = d0[mx]; int d = d0[mx]; map<int, vector<int>> groups; for (int i = 1; i < n; ++i) if (i != mx) { d1[i] = getDistance(mx, i); groups[(d1[i] - d0[i] + d0[mx]) / 2].push_back(i); d = max(d, d1[i]); } int hub = 0, lft = 1, rht = n-1; for (auto g: groups) { R = min(R, max(g.first, d-g.first)); } // cerr << mx << endl; for (auto g: groups) { rht -= g.second.size(); if (max(g.first, d-g.first) == R) { if (lft <= n/2 && rht <= n/2) { int mst = 0, cnt=0, qcnt=0; auto same_st = [&](int a, int b) {qcnt++;return a == b || getDistance(a, b) != d1[a]+d1[b] - 2*g.first;}; for (int i = 1; i < g.second.size(); ++i) { if (!cnt) mst = g.second[i]; if (same_st(mst, g.second[i])) { cnt++; } else { cnt--; } } int sz = 1; for (int i = g.second.size(); i--;) if (g.second[i] != mst) { if (same_st(mst, g.second[i])) { sz++; } } if (sz > n/2) return -R; return R; } } lft += g.second.size(); } return -R; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:26:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   26 |   rht -= g.second.size();
      |                        ^
towns.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 1; i < g.second.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
towns.cpp:40:31: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   40 |     for (int i = g.second.size(); i--;) if (g.second[i] != mst) {
      |                  ~~~~~~~~~~~~~^~
towns.cpp:49:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   49 |   lft += g.second.size();
      |                        ^
towns.cpp:20:6: warning: unused variable 'hub' [-Wunused-variable]
   20 |  int hub = 0, lft = 1, rht = n-1;
      |      ^~~
towns.cpp:5:28: warning: unused parameter 'sub' [-Wunused-parameter]
    5 | int hubDistance(int n, int sub) {
      |                        ~~~~^~~
#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...