# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1026081 |
2024-07-17T14:06:59 Z |
faruk |
ICC (CEOI16_icc) |
C++17 |
|
86 ms |
652 KB |
// 90 pts
#include "icc.h"
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> pii;
vector<vector<int> > components;
bool query(vector<int> a, vector<int> b) {
int a_niz[a.size()], b_niz[b.size()];
for (int i = 0; i < a.size(); i++)
a_niz[i] = a[i];
for (int i = 0; i < b.size(); i++)
b_niz[i] = b[i];
return query(a.size(), b.size(), a_niz, b_niz);
}
void merge_components(int A, int B) {
int a, b;
for (int i = 0; i < components.size(); i++)
{
if (count(all(components[i]), A))
a = i;
if (count(all(components[i]), B))
b = i;
}
if (a > b)
swap(a, b);
vector<int> neww_component = components[a];
neww_component.insert(neww_component.end(), all(components[b]));
components.erase(components.begin() + b);
components.erase(components.begin() + a);
components.push_back(neww_component);
}
vector<int> expand_component_array(vector<int> me) {
vector<int> neww;
for (int i : me)
neww.insert(neww.end(), all(components[i]));
return neww;
}
bool components_query(vector<int> a, vector<int> b) {
vector<int> newa = expand_component_array(a), newb = expand_component_array(b);
return query(newa, newb);
}
pii find_edge_from_true_query(vector<int> a, vector<int> b) {
pii out;
int l = 0, r = a.size();
while (l < r) {
int mid = (l + r) / 2;
if (query(vector<int>(a.begin(), a.begin() + mid + 1), b))
r = mid, out.first = mid;
else
l = mid + 1;
}
l = 0, r = b.size();
while (l < r) {
int mid = (l + r) / 2;
if (query(a, vector<int>(b.begin(), b.begin() + mid + 1)))
r = mid, out.second = mid;
else
l = mid + 1;
}
return pii(a[out.first], b[out.second]);
}
void run(int n) {
for (int i = 1; i <= n; i++)
components.push_back(vector<int>(1, i));
for (int i = 0; i < n - 1; i++) {
int max_bit = __lg(n - i) + 1;
vector<int> bits(max_bit);
iota(all(bits), 0);
//random_shuffle(all(bits));
vector<int> find_a, find_b;
for (int bit : bits)
{
vector<int> cmp1, cmp2;
for (int i = 0; i < components.size(); i++)
{
if (i & (1 << bit))
cmp1.push_back(i);
else
cmp2.push_back(i);
}
if (components_query(cmp1, cmp2)) {
find_a = expand_component_array(cmp1), find_b = expand_component_array(cmp2);
break;
}
}
pii edge = find_edge_from_true_query(find_a, find_b);
setRoad(edge.first, edge.second);
merge_components(edge.first, edge.second);
}
}
Compilation message
icc.cpp: In function 'bool query(std::vector<int>, std::vector<int>)':
icc.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
icc.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < b.size(); i++)
| ~~^~~~~~~~~~
icc.cpp: In function 'void merge_components(int, int)':
icc.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < components.size(); i++)
| ~~^~~~~~~~~~~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:87:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int i = 0; i < components.size(); i++)
| ~~^~~~~~~~~~~~~~~~~~~
icc.cpp: In function 'void merge_components(int, int)':
icc.cpp:30:5: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
30 | if (a > b)
| ^~
icc.cpp:30:5: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Ok! 108 queries used. |
2 |
Correct |
4 ms |
604 KB |
Ok! 111 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
644 KB |
Ok! 525 queries used. |
2 |
Correct |
25 ms |
604 KB |
Ok! 668 queries used. |
3 |
Correct |
25 ms |
436 KB |
Ok! 679 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
652 KB |
Ok! 1422 queries used. |
2 |
Correct |
77 ms |
640 KB |
Ok! 1649 queries used. |
3 |
Correct |
81 ms |
604 KB |
Ok! 1669 queries used. |
4 |
Correct |
75 ms |
604 KB |
Ok! 1509 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
640 KB |
Ok! 1606 queries used. |
2 |
Correct |
75 ms |
604 KB |
Ok! 1571 queries used. |
3 |
Correct |
79 ms |
600 KB |
Ok! 1650 queries used. |
4 |
Correct |
72 ms |
600 KB |
Ok! 1522 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
604 KB |
Ok! 1646 queries used. |
2 |
Correct |
77 ms |
600 KB |
Ok! 1649 queries used. |
3 |
Correct |
86 ms |
600 KB |
Ok! 1658 queries used. |
4 |
Correct |
82 ms |
604 KB |
Ok! 1644 queries used. |
5 |
Correct |
70 ms |
648 KB |
Ok! 1464 queries used. |
6 |
Correct |
74 ms |
652 KB |
Ok! 1544 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
648 KB |
Too many queries! 1677 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |