Submission #1040013

#TimeUsernameProblemLanguageResultExecution timeMemory
1040013c2zi6Towns (IOI15_towns)C++14
35 / 100
14 ms348 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "towns.h" int maxind(VL& a) { int ret; ll mx = -1e18; rep(i, a.size()) if (a[i] > mx) { mx = a[i]; ret = i; } return ret; } int hubDistance(int N, int SUBTASK) { int q = 0; int n = N; VL dist0, distd1, distd2, distl, distr, disth; dist0 = distd1 = distd2 = distl = distr = disth = VL(n); rep(u, n) dist0[u] = getDistance(0, u), q++; int d1 = maxind(dist0); rep(u, n) distd1[u] = getDistance(d1, u), q++; int d2 = maxind(distd1); rep(u, n) distd2[u] = getDistance(d2, u), q++; ll R = 1e18; rep(u, n) { disth[u] = (distd1[u] + distd2[u] - distd1[d2])/2; distl[u] = distd1[u]-disth[u]; distr[u] = distd2[u]-disth[u]; setmin(R, max(distl[u], distr[u])); } VI anc(n); /* 0, on the left * 1, first hub * 2, second hub * 3, on the right */ rep(u, n) { if (max(distl[u], distr[u]) == R) { if (distl[u] <= distr[u]) anc[u] = 1; else anc[u] = 2; } else { if (distl[u] <= distr[u]) anc[u] = 0; else anc[u] = 3; } } int cnt[4]{}; for (int x : anc) cnt[x]++; if (SUBTASK == 4) { if (cnt[0] <= N/2 && cnt[1] <= N/2 && cnt[2] + cnt[3] <= N/2) return +R; if (cnt[0] + cnt[1] <= N/2 && cnt[2] <= N/2 && cnt[3] <= N/2) return +R; return -R; } else if (SUBTASK == 3) { auto check = [&](int u, int v) { return disth[u] + disth[v] != getDistance(u, v), q++; }; VI a; replr(HUBIND, 1, 2) { a = VI(); rep(i, n) if (anc[i] == HUBIND) a.pb(i); if (a.size() == 0) continue; VI subtrees; subtrees.pb(cnt[0]); subtrees.pb(cnt[3]); VI group(n); int g = 1; for (int i : a) if (group[i] == 0) { group[i] = g; subtrees.pb(1); for (int j : a) if (group[j] == 0) { if (check(i, j)) { group[j] = g; subtrees.back()++; } } g++; } bool good = true; for (int x : subtrees) { if (x > N/2) good = false; } if (good) { assert(q <= N * (N-1) /2); return -R; } } assert(q <= N * (N-1) /2); return +R; } return -R; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:82:78: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   82 |         if (cnt[0] <= N/2 && cnt[1] <= N/2 && cnt[2] + cnt[3] <= N/2) return +R;
      |                                                                              ^~
towns.cpp:83:78: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   83 |         if (cnt[0] + cnt[1] <= N/2 && cnt[2] <= N/2 && cnt[3] <= N/2) return +R;
      |                                                                              ^~
towns.cpp:84:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   84 |         return -R;
      |                ^~
towns.cpp: In lambda function:
towns.cpp:87:40: warning: value computed is not used [-Wunused-value]
   87 |             return disth[u] + disth[v] != getDistance(u, v), q++;
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:119:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  119 |                 return -R;
      |                        ^~
towns.cpp:123:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  123 |         return +R;
      |                ^~
towns.cpp:125:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  125 |  return -R;
      |         ^~
towns.cpp: In function 'int maxind(VL&)':
towns.cpp:41:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     return ret;
      |            ^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:58:54: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         disth[u] = (distd1[u] + distd2[u] - distd1[d2])/2;
      |                                                      ^
towns.cpp:52:38: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     rep(u, n) distd1[u] = getDistance(d1, u), q++;
      |                           ~~~~~~~~~~~^~~~~~~
#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...