# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60648 |
2018-07-24T13:08:15 Z |
reality |
Towns (IOI15_towns) |
C++17 |
|
40 ms |
908 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) {
srand(time(0));
const int root = rand() % n;
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(root,i) > get(root,x))
x = i;
int y = x;
for (int i = 0;i < n;++i)
if (get(x,i) > get(x,y))
y = i;
vi s;
for (int k = 0;k < n;++k)
s.pb((get(root,x) - get(root,k) + get(x,k)) / 2);
sort(all(s));
int dist = -1;
int ans = 2e9;
for (auto it : s)
smin(ans,max(it,get(x,y) - it));
for (auto it : s)
if (max(it,get(x,y) - it) == ans)
dist = it;
int a = 0,b = 0;
vi was(n,0);
for (int k = 0;k < n;++k) {
int df = get(x,k) - get(root,k);
int sm = get(root,x);
if (df + sm < 2 * dist)
was[k] = 1,++a;
else
if (df + sm > 2 * dist)
was[k] = 1,++b;
}
if (max(a,b) > (n / 2))
return -ans;
vi v;
auto ok = [&](int A,int B) {
return get(A,B) != get(A,x) + get(B,x) - 2 * dist;
};
int cnt = 0,cur = -1;
for (int i = 0;cnt <= (n / 2) && i < n;++i)
if (!was[i]) {
if (!cnt) {
cnt = 1;
cur = i;
} else
if (ok(cur,i))
++cnt;
else
--cnt;
}
if (cnt > (n / 2))
return -ans;
int nr = 0;
for (int i = 0;i < n;++i)
if (!was[i])
nr += ok(cur,i);
if (nr <= (n / 2))
return ans;
else
return -ans;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:29:12: warning: conversion to 'unsigned int' from 'time_t {aka long int}' may alter its value [-Wconversion]
srand(time(0));
~~~~^~~
towns.cpp:28:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int n, int sub) {
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
632 KB |
Output is correct |
2 |
Correct |
23 ms |
872 KB |
Output is correct |
3 |
Correct |
2 ms |
872 KB |
Output is correct |
4 |
Correct |
40 ms |
872 KB |
Output is correct |
5 |
Correct |
25 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
872 KB |
Output is correct |
2 |
Incorrect |
13 ms |
872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |