# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1085225 |
2024-09-07T17:30:51 Z |
Fran |
ICC (CEOI16_icc) |
C++17 |
|
3 ms |
604 KB |
#include<bits/stdc++.h>
#include "icc.h"
using namespace std;
using pii = pair<int, int>;
constexpr int NN = 101;
constexpr int K = 7;
bitset<NN> bits[NN], was;
int id[NN], siz[NN], A[NN], A_temp[NN], B[NN], B_temp[NN];
vector<int> members[NN];
void run(int N) {
for(int i = 1; i <= N; ++i) {
id[i] = i;
members[i].emplace_back(i);
siz[i] = 1;
}
auto compute_bits = []() {
for(int i = 1; i <= NN; i++) {
int number = i;
int cnt = 0;
while(number > 0) {
bits[i][cnt++] = number%2;
number >>= 1;
}
}
};
compute_bits();
auto find = [&](int x, auto&& find) -> int {
return (id[x] != x) ? id[x] = find(id[x], find) : x;
};
auto join_vectors = [](int a, int b) {
for(auto& s : members[b]) {
members[a].emplace_back(s);
members[b].pop_back();
}
};
auto join_sets = [&](int a, int b) {
a = find(a, find);
b = find(b, find);
if(a == b) return;
if(siz[a] < siz[b]) swap(a, b);
siz[a] += siz[b];
siz[b] = 0;
id[b] = a;
join_vectors(a, b);
};
for(int tour = 0; tour < N - 1; ++tour) {
int a_node{-1}, b_node{-1};
int a_siz{0}, b_siz{0};
bool found = 0;
for(int k = 0; k < K; ++k) {
a_siz = 0,
b_siz = 0;
for(int i = 0; i <= N; ++i) was[i] = 0;
for(int cur = 1; cur <= N; ++cur) {
cur = find(cur, find);
if(was[cur]) continue;
was[cur] = 1;
if(bits[cur][k]){
for(auto& member : members[cur])
A[a_siz++] = member;
}
else {
for(auto& member : members[cur])
B[b_siz++] = member;
}
}
if(query(a_siz, b_siz, A, B)) break;
}
int l_a{0}, r_a{a_siz};
while(r_a - l_a > 1) {
int mid = l_a + (r_a-l_a)/2;
int temp_siz{0};
for(int i = l_a; i < mid; ++i) A_temp[temp_siz++] = A[i];
if(query(temp_siz, b_siz, A_temp, B)) r_a = mid;
else {
l_a = mid;
}
}
a_node = A[l_a];
int l_b{0}, r_b{b_siz};
while(r_b - l_b > 1) {
int mid = l_b + (r_b-l_b)/2;
int temp_siz{0};
for(int i = l_b; i < mid; ++i) B_temp[temp_siz++] = B[i];
if(query(a_siz, temp_siz, A, B_temp)) r_b = mid;
else l_b = mid;
}
b_node = B[l_b];
setRoad(a_node, b_node);
}
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:59:10: warning: unused variable 'found' [-Wunused-variable]
59 | bool found = 0;
| ^~~~~
icc.cpp:44:8: warning: variable 'join_sets' set but not used [-Wunused-but-set-variable]
44 | auto join_sets = [&](int a, int b) {
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
604 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
600 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |