# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
688540 |
2023-01-27T16:35:16 Z |
nhphucqt |
ICC (CEOI16_icc) |
C++17 |
|
128 ms |
262144 KB |
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
const int N = 107;
int fa[N];
int nTotal, nLef, nRig;
int total[N], lef[N], rig[N];
int tnLef, tnRig;
int tmpLef[N], tmpRig[N];
vector<int> comp[N];
int root (int x) {
return fa[x] < 0 ? x : fa[x] = root(fa[x]);
}
void unite(int u, int v) {
if (fa[u] > fa[v]) {
swap(u, v);
}
fa[u] += fa[v];
fa[v] = u;
for (int x : comp[v]) {
comp[u].push_back(x);
}
}
void arrCopy(int sizA, int A[], int &sizB, int B[]) {
for (int i = 0; i < sizA; ++i) {
B[i] = A[i];
}
sizB = sizA;
}
void divide(int sizA, int A[], int &sizB, int B[], int &sizC, int C[]) {
sizB = sizC = 0;
for (int i = 0; i < sizA/2; ++i) {
B[sizB++] = A[i];
}
for (int i = sizA/2; i < sizA; ++i) {
C[sizC++] = A[i];
}
}
void makeQuery() {
while (nLef > 1 || nRig > 1) {
tnLef = tnRig = 0;
for (int i = (nLef+1)/2; i < nLef; ++i) {
tmpLef[tnLef++] = lef[i];
}
for (int i = (nRig+1)/2; i < nRig; ++i) {
tmpRig[tnRig++] = rig[i];
}
nLef = (nLef+1)/2;
nRig = (nRig+1)/2;
if (query(nLef, tnRig, lef, tmpRig) == 1) {
arrCopy(tnRig, tmpRig, nRig, rig);
} else if (query(tnLef, nRig, tmpLef, rig) == 1) {
arrCopy(tnLef, tmpLef, nLef, lef);
} else if (query(tnLef, tnRig, tmpLef, tmpRig) == 1) {
arrCopy(tnLef, tmpLef, nLef, lef);
arrCopy(tnRig, tmpRig, nRig, rig);
}
// cerr << "Make query: " << query(nLef, nRig, lef, rig) << '\n';
}
}
void run(int numNode) {
memset(fa, -1, (numNode+1) * sizeof(int));
for (int i = 1; i <= numNode; ++i) {
comp[i].push_back(i);
}
int numComp = numNode;
while (numComp-- > 1) {
nTotal = 0;
for (int i = 1; i <= numNode; ++i) {
if (i == root(i)) {
total[nTotal++] = i;
}
}
// cerr << "Total : ";
// for (int i = 0; i < nTotal; ++i) {
// cerr << total[i] << ' ';
// } cerr << '\n';
for (int j = 0; j < 4; ++j) {
nLef = nRig = 0;
for (int i = 0; i < nTotal; ++i) {
if ((i>>j) & 1) {
for (int x : comp[total[i]]) {
lef[nLef++] = x;
}
} else {
for (int x : comp[total[i]]) {
rig[nRig++] = x;
}
}
}
// cerr << "lef: ";
// for (int i = 0; i < nLef; ++i) {
// cerr << lef[i] << ' ';
// }
// cerr << '\n';
// cerr << "rig: ";
// for (int i = 0; i < nRig; ++i) {
// cerr << rig[i] << ' ';
// }
// cerr << '\n';
if (query(nLef, nRig, lef, rig) == 1) {
break;
}
// cerr << "---\n";
}
// cerr << "First term: " << query(nLef, nRig, lef, rig) << '\n';
makeQuery();
int rootA = root(lef[0]);
int rootB = root(rig[0]);
nLef = nRig = 0;
for (int i = 1; i <= numNode; ++i) {
if (root(i) == rootA) {
lef[nLef++] = i;
} else if (root(i) == rootB) {
rig[nRig++] = i;
}
}
makeQuery();
assert(nLef == 1 && nRig == 1);
// cerr << query(nLef, nRig, lef, rig) << '\n';
// cerr << "Set road: " << lef[0] << ' ' << rig[0] << '\n';
setRoad(lef[0], rig[0]);
unite(lef[0], rig[0]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
128 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |