# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1072082 |
2024-08-23T14:07:00 Z |
adaawf |
ICC (CEOI16_icc) |
C++17 |
|
129 ms |
852 KB |
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
int p[105], s[105];
vector<int> v[105];
int Find(int x) {
if (x == p[x]) return x;
return p[x] = Find(p[x]);
}
void Merge(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
if (s[x] < s[y]) swap(x, y);
s[x] += s[y];
p[y] = x;
}
/*int query(int n, int m, int a[], int b[]) {
cout << n << " " << m << endl;
for (int i = 0; i < n; i++) cout << a[i] << " ";
cout << endl;
for (int i = 0; i < m; i++) cout << b[i] << " ";
cout << endl;
int k;
cin >> k;
return k;
}*/
int query(vector<int> a, vector<int> b) {
int c[a.size()], d[b.size()];
for (int i = 0; i < a.size(); i++) c[i] = a[i];
for (int i = 0; i < b.size(); i++) d[i] = b[i];
return query(a.size(), b.size(), c, d);
}
void run(int n) {
unsigned rr = std::chrono::system_clock::now().time_since_epoch().count();
for (int i = 1; i <= n; i++) {
p[i] = i;
s[i] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= n; j++) {
v[j].clear();
}
for (int j = 1; j <= n; j++) {
int h = Find(j);
v[h].push_back(j);
}
vector<int> vv, va, vb;
for (int j = 1; j <= n; j++) {
if (!v[j].empty()) {
vv.push_back(j);
}
}
shuffle(vv.begin(), vv.end(), default_random_engine(rr));
for (int j = 0; j < 7; j++) {
vector<int> a, b;
for (int i = 0; i < vv.size(); i++) {
int w = vv[i];
if (i & (1 << j)) {
for (int ww : v[w]) a.push_back(ww);
}
else {
for (int ww : v[w]) b.push_back(ww);
}
}
if (a.empty() || b.empty()) continue;
if (query(a, b)) {
va = a;
vb = b;
break;
}
}
shuffle(va.begin(), va.end(), default_random_engine(rr));
shuffle(vb.begin(), vb.end(), default_random_engine(rr));
int l = 0, r = va.size() - 1, res;
while (l != r) {
int mid = (l + r) / 2;
vector<int> vc;
for (int i = l; i <= mid; i++) {
vc.push_back(va[i]);
}
if (query(vc, vb)) {
r = mid;
}
else l = mid + 1;
}
res = l;
l = 0; r = vb.size() - 1;
while (l != r) {
int mid = (l + r) / 2;
vector<int> vc;
for (int i = l; i <= mid; i++) {
vc.push_back(vb[i]);
}
if (query(va, vc)) {
r = mid;
}
else l = mid + 1;
}
setRoad(va[res], vb[l]);
Merge(va[res], vb[l]);
}
}
/*int main() {
run(4);
}*/
Compilation message
icc.cpp: In function 'int query(std::vector<int>, std::vector<int>)':
icc.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < a.size(); i++) c[i] = a[i];
| ~~^~~~~~~~~~
icc.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < b.size(); i++) d[i] = b[i];
| ~~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < vv.size(); i++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Ok! 103 queries used. |
2 |
Correct |
4 ms |
636 KB |
Ok! 100 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
604 KB |
Ok! 535 queries used. |
2 |
Correct |
27 ms |
600 KB |
Ok! 646 queries used. |
3 |
Correct |
26 ms |
604 KB |
Ok! 635 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
600 KB |
Ok! 1399 queries used. |
2 |
Correct |
87 ms |
852 KB |
Ok! 1595 queries used. |
3 |
Correct |
76 ms |
600 KB |
Ok! 1507 queries used. |
4 |
Correct |
80 ms |
604 KB |
Ok! 1496 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
604 KB |
Ok! 1508 queries used. |
2 |
Correct |
77 ms |
636 KB |
Ok! 1479 queries used. |
3 |
Correct |
96 ms |
604 KB |
Ok! 1588 queries used. |
4 |
Correct |
72 ms |
600 KB |
Ok! 1430 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
604 KB |
Ok! 1581 queries used. |
2 |
Correct |
91 ms |
632 KB |
Ok! 1569 queries used. |
3 |
Correct |
83 ms |
624 KB |
Ok! 1601 queries used. |
4 |
Correct |
86 ms |
600 KB |
Ok! 1596 queries used. |
5 |
Correct |
73 ms |
640 KB |
Ok! 1435 queries used. |
6 |
Correct |
88 ms |
632 KB |
Ok! 1511 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
600 KB |
Ok! 1595 queries used. |
2 |
Correct |
129 ms |
600 KB |
Ok! 1619 queries used. |