# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302423 | square1001 | Towns (IOI15_towns) | C++14 | 28 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "towns.h"
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int hubDistance(int N, int sub) {
if(sub == 1 || sub == 2) {
vector<int> da(N);
for(int i = 1; i < N; ++i) {
da[i] = getDistance(0, i);
}
int ma = max_element(da.begin(), da.end()) - da.begin();
vector<int> db(N);
for(int i = 0; i < N; ++i) {
if(i != ma) {
db[i] = getDistance(ma, i);
}
}
int mb = max_element(db.begin(), db.end()) - db.begin();
int mindiff = (1 << 30);
for(int i = 0; i < N; ++i) {
if(i != ma && i != mb) {
int dy = getDistance(mb, i);
mindiff = min(mindiff, abs(db[i] - dy));
}
}
return (db[mb] + mindiff) / 2;
}
if(sub == 4) {
vector<int> da(N);
for(int i = 1; i < N; ++i) {
da[i] = getDistance(0, i);
}
int ma = max_element(da.begin(), da.end()) - da.begin();
vector<int> db(N);
for(int i = 0; i < N; ++i) {
if(i != ma) {
db[i] = getDistance(ma, i);
}
}
int mb = max_element(db.begin(), db.end()) - db.begin();
vector<int> ds(N);
int mindiff = (1 << 30);
for(int i = 0; i < N; ++i) {
int dy = getDistance(mb, i);
ds[i] = db[i] - dy;
mindiff = min(mindiff, abs(ds[i]));
}
int R = (db[mb] + mindiff) / 2;
int cl1 = 0, cm1 = 0, cr1 = 0;
for(int i = 0; i < N; ++i) {
if(ds[i] < mindiff) ++cl1;
else if(ds[i] == mindiff) ++cm1;
else ++cr1;
}
if(cm1 >= 1 && cl1 <= N / 2 && cm1 <= N / 2 && cr1 <= N / 2) {
return R;
}
int cl2 = 0, cm2 = 0, cr2 = 0;
for(int i = 0; i < N; ++i) {
if(ds[i] < -mindiff) ++cl2;
else if(ds[i] == -mindiff) ++cm2;
else ++cr2;
}
if(cm2 >= 1 && cl2 <= N / 2 && cm2 <= N / 2 && cr2 <= N / 2) {
return R;
}
return -R;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |