# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60228 |
2018-07-23T22:00:00 Z |
reality |
Towns (IOI15_towns) |
C++17 |
|
33 ms |
928 KB |
#include "towns.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 256;
int D[N][N];
int get(int x,int y) {
if (D[x][y] != -1)
return D[x][y];
return D[x][y] = D[y][x] = getDistance(x,y);
}
int hubDistance(int n, int sub) {
memset(D,-1,sizeof(D));
int x = 0;
for (int i = 0;i < n;++i)
D[i][i] = 0;
for (int i = 0;i < n;++i)
if (get(0,i) > get(0,x))
x = i;
int y = x;
for (int i = 0;i < n;++i)
if (get(x,i) > get(x,y))
y = i;
vi s;
map < int , int > M;
for (int k = 0;k < n;++k)
s.pb((get(x,y) - (get(x,k) - get(y,k))) / 2),++M[s.back()];
sort(all(s));
s.resize(unique(all(s)) - s.begin());
int ans = 2e9;
for (auto it : s)
smin(ans,max(it,D[x][y] - it));
//if (sub <= 2)
// return ans;
for (auto dist : s)
if (max(dist,D[x][y] - dist) == ans) {
int a = 0,b = 0;
for (auto it : M) {
if (it.fi < dist)
a += it.se;
if (dist < it.fi)
b += it.se;
}
vi v;
for (int k = 0;k < n;++k)
if (get(x,y) - (get(x,k) - get(y,k)) == 2 * dist)
v.pb(k);
int sz = v.size();
int c = 0;
for (int k = 1;k < sz;++k)
if (get(y,v[k]) + get(y,v[0]) - get(v[0],v[k]) == 2 * dist)
++c;
int d = n - a - b - c;
if (max({a,b,c,d}) <= (n / 2))
return ans;
}
return -ans;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:64:19: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
int sz = v.size();
~~~~~~^~
towns.cpp:28:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int n, int sub) {
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
632 KB |
Output is correct |
2 |
Correct |
19 ms |
632 KB |
Output is correct |
3 |
Correct |
3 ms |
648 KB |
Output is correct |
4 |
Correct |
23 ms |
724 KB |
Output is correct |
5 |
Correct |
26 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
800 KB |
Output is correct |
2 |
Correct |
26 ms |
800 KB |
Output is correct |
3 |
Correct |
33 ms |
800 KB |
Output is correct |
4 |
Correct |
24 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
928 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |