# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60688 |
2018-07-24T14:18:18 Z |
reality |
Towns (IOI15_towns) |
C++17 |
|
34 ms |
1236 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 dist[666];
int ans = 2e9;
int x = 0;
int n;
int go(int dt) {
vi was(n,1);
int a = 0,b = 0;
for (int i = 0;i < n;++i) {
int curr = get(x,i) - dist[i];
if (curr < dt)
++a,was[i] = 0;
if (curr > dt)
++b,was[i] = 0;
}
if (max({a,b}) > (n / 2))
return -ans;
auto ok = [&](int A,int B) {
return get(A,B) != dist[A] + dist[B];
};
int cnt = 0;
int cur = -1;
vector < pii > ss;
for (int i = 0;cnt <= (n / 2) && i < n;++i)
if (was[i]) {
if (!cnt) {
cur = i;
cnt = 1;
ss.pb(mp(cur,1));
} else
if (ok(cur,i)) {
++cnt;
++ss.back().se;
} else {
--cnt;
++ss.back().se;
}
}
cnt = (cnt + ss.back().se) / 2;
int sz = ss.size();
for (int i = 0;i + 1 < sz;++i) {
if (ok(cur,ss[i].fi))
cnt += ss[i].se / 2;
else {
for (int j = ss[i].fi;j < ss[i].fi + ss[i].se;++j)
if (!ok(ss[i].fi,j)) {
cnt += ok(cur,j);
}
}
}
if (cnt <= (n / 2))
return ans;
else
return -ans;
}
int hubDistance(int N, int sub) {
n = N;
srand(time(0));
const int root = 0;
memset(D,-1,sizeof(D));
for (int i = 0;i < n;++i)
D[i][i] = 0;
x = root;
ans = 2e9;
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;
const int Diam = get(x,y);
int t = -1;
for (int i = 0;i < n;++i) {
dist[i] = (get(root,i) + get(x,i) - get(root,x)) / 2;
int dx = get(x,i) - dist[i];
smin(ans,max(Diam - dx,dx));
if (max(Diam - dx,dx) == ans)
t = dx;
}
return max(go(t),go(Diam - t));
}
Compilation message
towns.cpp: In function 'int go(int)':
towns.cpp:70:18: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
int sz = ss.size();
~~~~~~~^~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:87:31: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int hubDistance(int N, int sub) {
^
towns.cpp:18:11: note: shadowed declaration is here
const int N = 256;
^
towns.cpp:89:12: warning: conversion to 'unsigned int' from 'time_t {aka long int}' may alter its value [-Wconversion]
srand(time(0));
~~~~^~~
towns.cpp:87:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int N, int sub) {
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
632 KB |
Output is correct |
2 |
Runtime error |
3 ms |
1128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1132 KB |
Output is correct |
2 |
Runtime error |
4 ms |
1132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1164 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
1224 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1236 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1236 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |