# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
35100 |
2017-11-18T04:45:03 Z |
imeimi2000 |
Towns (IOI15_towns) |
C++14 |
|
19 ms |
1220 KB |
#include "towns.h"
#include <vector>
#include <algorithm>
using namespace std;
int n;
int d0[110];
int d1[110];
int dist[110];
bool checkSame(int i, int j) {
return (getDistance(i, j) != dist[i] + dist[j]);
}
bool chk[110];
bool check(int p) {
int l = 0, r = 0;
vector<int> vt;
for (int i = 0; i < n; ++i) {
if (d1[i] < d1[p]) ++l;
else if (d1[i] > d1[p]) ++r;
else vt.push_back(i);
}
if (l > n / 2 || r > n / 2) return false;
int st, sum = 0;
vector<int> gr;
for (int i = 0; i < vt.size(); ++i) {
if (sum == 0) {
gr.push_back(st = i);
sum = 1;
}
else {
if (chk[i] = checkSame(st, i)) ++sum;
else --sum;
}
}
sum = (sum + (vt.size() - st)) / 2;
for (int i = 1; i < gr.size(); ++i) {
if (checkSame(gr[i - 1], st)) sum += (gr[i] - gr[i - 1]) / 2;
else {
for (int j = gr[i - 1] + 1; j < gr[i]; ++j) {
if (chk[j]) continue;
if (checkSame(j, st)) ++sum;
}
}
}
return sum <= n / 2;
}
int hubDistance(int N, int sub) {
n = N;
int p = 0, d = 0;
for (int i = 1; i < n; ++i) {
d0[i] = getDistance(0, i);
if (d < d0[i]) {
d = d0[i];
p = i;
}
}
d1[0] = d;
d1[p] = 0;
for (int i = 1; i < n; ++i) {
if (i == p) continue;
d1[i] = getDistance(p, i);
d = max(d1[i], d);
}
int r = 2e9;
for (int i = 1; i < n; ++i) {
if (i == p) continue;
dist[i] = d0[i] + d1[i] - d;
r = min(r, abs(d - 2 * (d1[i] - dist[i])));
}
int ans = (d + r) / 2;
for (int i = 1; i < n; ++i) {
if (i == p) continue;
if (r == abs(d - 2 * (d1[i] - dist[i])) && check(i)) return ans;
}
return -ans;
}
Compilation message
towns.cpp: In function 'bool check(int)':
towns.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vt.size(); ++i) {
^
towns.cpp:35:33: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (chk[i] = checkSame(st, i)) ++sum;
^
towns.cpp:39:6: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
sum = (sum + (vt.size() - st)) / 2;
^
towns.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < gr.size(); ++i) {
^
towns.cpp: At global scope:
towns.cpp:52:28: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int N, int sub) {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
1220 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |