제출 #411301

#제출 시각아이디문제언어결과실행 시간메모리
411301ja_kingy도시들 (IOI15_towns)C++14
100 / 100
20 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 = -1, cnt=0, qcnt=0; vector<int> head(n), not_same(n,-1), sz(n); auto same_st = [&](int a, int b) {qcnt++;return a == b || getDistance(a, b) != d1[a]+d1[b] - 2*g.first;}; for (int i = 0; i < g.second.size(); ++i) { if (!cnt) mst = g.second[i]; if (same_st(mst, g.second[i])) { cnt++; head[g.second[i]] = mst; sz[mst]++; } else { cnt--; not_same[g.second[i]] = mst; head[g.second[i]] = g.second[i]; sz[g.second[i]] = 1; } } bool ignore = 0; for (int i = g.second.size(); i--;) if (g.second[i] != mst) { if (head[g.second[i]] == g.second[i]) { if (same_st(mst, g.second[i])) { sz[mst]+=sz[g.second[i]]; /*if (~not_same[g.second[i]]) { ignore = 1; }*/ } } } 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: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:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < g.second.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
towns.cpp:46:31: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   46 |     for (int i = g.second.size(); i--;) if (g.second[i] != mst) {
      |                  ~~~~~~~~~~~~~^~
towns.cpp:45:10: warning: unused variable 'ignore' [-Wunused-variable]
   45 |     bool ignore = 0;
      |          ^~~~~~
towns.cpp:60:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   60 |   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...