# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
717879 | stevancv | ICC (CEOI16_icc) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
#include "icc.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 100 + 2;
const int inf = 1e9;
vector<int> svi[N];
void Nadji(vector<int> a, vector<int> b) {
cout << "THU" << endl;
int l = 0, r = a.size() - 2, xx = a.back();
while (l <= r) {
int mid = l + r >> 1;
vector<int> tr;
for (int i = 0; i <= mid; i++) tr.push_back(a[i]);
if (query(mid + 1, b.size(), tr, b) == 1) {
xx = a[mid];
r = mid - 1;
}
else l = mid + 1;
}
l = 0, r = b.size() - 2;
int yy = b.back();
while (l <= r) {
int mid = l + r >> 1;
vector<int> tr;
for (int i = 0; i <= mid; i++) tr.push_back(b[i]);
if (query(mid + 1, 1, tr, {xx}) == 1) {
yy = b[mid];
r = mid - 1;
}
else l = mid + 1;
}
setRoad(xx, yy);
}
int gazda[N];
void run(int n) {
vector<int> v;
for (int i = 1; i <= n; i++) {
svi[i].push_back(i);
gazda[i] = 1;
}
auto Sredi = [&] (vector<int> v) {
vector<int> ret;
for (int i = 0; i < v.size(); i++) {
for (int j : svi[v[i]]) ret.push_back(j);
}
return ret;
};
for (int zz = 0; zz < n - 1; zz++) {
vector<int> v;
for (int i = 1; i <= n; i++) {
if (gazda[i] == 1) v.push_back(i);
}
int sz = v.size();
vector<int> a, b;
while (1) {
random_shuffle(v.begin(), v.end());
for (int i = 0; i < sz / 2; i++) a.push_back(v[i]);
for (int i = sz / 2; i < sz; i++) b.push_back(v[i]);
auto aa = Sredi(a); auto bb = Sredi(b);
if (query(aa.size(), bb.size(), aa, bb) == 1) break;
else {a.clear(); b.clear();}
}
int l = 0, r = a.size() - 2, inda = a.back();
auto bb = Sredi(b);
while (l <= r) {
int mid = l + r >> 1;
vector<int> tr;
for (int i = 0; i <= mid; i++) tr.push_back(a[i]);
auto ttr = Sredi(tr);
if (query(ttr.size(), bb.size(), ttr, bb) == 1) {
inda = a[mid];
r = mid - 1;
}
else l = mid + 1;
}
l = 0, r = b.size() - 2;
int indb = b.back();
auto aa = Sredi({inda});
while (l <= r) {
int mid = l + r >> 1;
vector<int> tr;
for (int i = 0; i <= mid; i++) tr.push_back(b[i]);
auto ttr = Sredi(tr);
if (query(aa.size(), ttr.size(), aa, tr) == 1) {
indb = b[mid];
r = mid - 1;
}
else l = mid + 1;
}
Nadji(svi[inda], svi[indb]);
if (inda > indb) swap(inda, indb);
for (int i : svi[indb]) {
svi[inda].push_back(i);
gazda[i] = 0;
}
svi[indb].clear();
}
}