제출 #410980

#제출 시각아이디문제언어결과실행 시간메모리
410980ja_kingy도시들 (IOI15_towns)C++14
25 / 100
28 ms356 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)); } for (auto g: groups) { rht -= g.second.size(); if (max(g.first, d-g.first) == R) { if (lft <= n/2 && rht <= n/2) { vector<int> head(n), sz(n,1); int mst = g.second[0], cnt=1, qcnt=0; auto same_st = [&](int a, int b) {qcnt++;return getDistance(a, b) != d1[a]+d1[b] - 2*g.first;}; for (int i = 1; i < g.second.size(); ++i) { if (same_st(mst, g.second[i])) { cnt++; head[i] = mst; sz[mst]++; } else { if (cnt == 0) { mst = g.second[i]; head[mst] = mst; cnt = 1; } else cnt--; } } for (int i = g.second.size(); i--;) { if (g.second[i] == head[g.second[i]]) { if (same_st(mst, g.second[i])) { sz[mst] += sz[g.second[i]]; } if (qcnt > n) return -R; } } if (sz[mst] >= n/2) return -R; return R; } } lft += g.second.size(); } return -R; }

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

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:25:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   25 |   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:44:31: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   44 |     for (int i = g.second.size(); i--;) {
      |                  ~~~~~~~~~~~~~^~
towns.cpp:56:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   56 |   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...