# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
875480 |
2023-11-19T21:36:55 Z |
LucaLucaM |
ICC (CEOI16_icc) |
C++17 |
|
143 ms |
964 KB |
#include "icc.h"
#ifdef LOCAL
#include "grader.cpp"
#endif // LOCAL
#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <functional>
#include <random>
#ifndef LOCAL
#define assert //assert
#endif // LOCAL
using vi = std::vector<int>;
const int NMAX = 100;
int p[NMAX + 1];
int root(int u) {
if (p[u] == u) {
return u;
}
return p[u] = root(p[u]);
}
void join(int u, int v) {
u = root(u), v = root(v);
p[u] = v;
}
int ask(vi a, vi b) {
if (a.empty() || b.empty()) {
return 0;
}
int sz_a = (int) a.size(), sz_b = (int) b.size();
int A[sz_a], B[sz_b];
for (int i = 0; i < sz_a; i++) {
A[i] = a[i];
}
for (int i = 0; i < sz_b; i++) {
B[i] = b[i];
}
return query(sz_a, sz_b, A, B);
}
int ask(std::vector<vi> a, vi b) {
if (a.empty() || b.empty()) {
return 0;
}
std::vector<int> A;
for (const auto &w : a) {
for (const auto &x : w) {
A.push_back(x);
}
}
return ask(A, b);
}
int ask(vi a, std::vector<vi> b) {
if (a.empty() || b.empty()) {
return 0;
}
std::vector<int> B;
for (const auto &w : b) {
for (const auto &x : w) {
B.push_back(x);
}
}
return ask(a, B);
}
int ask(std::vector<vi> a, std::vector<vi> b) {
if (a.empty() || b.empty()) {
return 0;
}
std::vector<int> B;
for (const auto &w : b) {
for (const auto &x : w) {
B.push_back(x);
}
}
return ask(a, B);
}
vi operator + (vi a, vi b) {
vi c = a;
for (const auto &x : b) {
c.push_back(x);
}
return c;
}
/**
setRoad() -> alege doua cc si le da join
daca eu aflu aceste doua cc => pot face doua cb si o sa am 2 * log query uri
daca fac brut si mereu incerc sa aflu o cc noua =>
in total ~n(n - 1) / 2 query uri ca sa aflu cc desi cred ca e putin mai bine ceva gen mai trebuie scazut 1 * n
intre doua cc sigur nu am muchie
daca bag gen query pe bucati de radical cu ce e in afara ar iesi si ar fi 2 * sqrt(m) cred, m = #cc
ok acm am realizat ca asta e proasta
spamam random shuffle pana prima jumate are una si a doua jumate are alta
**/
std::mt19937 rng(42); // cica a intrat bine asta la ejoi
void run(int n) {
for (int i = 1; i <= n; i++) {
p[i] = i;
}
for (int k = 1; k < n; k++) {
vi kk[n + 1];
int m = n - (k - 1);
for (int i = 1; i <= n; i++) {
kk[root(i)].push_back(i);
}
vi care;
for (int i = 1; i <= n; i++) {
if (!kk[i].empty()) {
care.push_back(i);
}
}
// std::cout << "SI UNA";
while (true) {
shuffle(care.begin(), care.end(), rng);
int sz = (int) care.size();
std::vector<vi> l, r;
for (int i = 0; i < sz / 2; i++) {
l.push_back(kk[care[i]]);
}
for (int i = sz / 2; i < sz; i++) {
r.push_back(kk[care[i]]);
}
if (ask(l, r) == 1) {
break;
}
}
// std::cout << "SI DOUA";
std::function<std::pair<int, int>(vi, vi) > get = [&] (vi a, vi b) { // SUS
assert(!a.empty() && !b.empty());
if ((int) a.size() == 1 && (int) b.size() == 1) {
return std::pair<int, int> {a[0], b[0]};
}
if ((int) a.size() == 1) {
vi as;
int i = 0;
for (i = 0; i < (int) b.size() / 2; i++) {
as.push_back(b[i]);
}
if (ask(a, as) == 1) {
assert((int) as.size() < (int) b.size());
return get(a, as);
} else {
as.clear();
while (i < (int) b.size()) {
as.push_back(b[i++]);
}
assert((int) as.size() < (int) b.size());
return get(a, as);
}
} else {
vi as;
int i = 0;
for (i = 0; i < (int) a.size() / 2; i++) {
as.push_back(a[i]);
}
if (ask(as, b) == 1) {
assert((int) as.size() < (int) a.size());
return get(as, b);
} else {
as.clear();
while (i < (int) a.size()) {
as.push_back(a[i++]);
}
assert((int) as.size() < (int) a.size());
return get(as, b);
}
}
};
std::function<std::pair<vi, vi>(std::vector<vi>, std::vector<vi>) > get2 = [&] (std::vector<vi> a, std::vector<vi> b) { // SUS
// std::cout << "??? " << (int) a.size() << ' ' << (int) b.size() << '\n';
assert(!a.empty() && !b.empty());
if ((int) a.size() == 1 && (int) b.size() == 1) {
return std::pair<vi, vi> {a[0], b[0]};
}
if ((int) a.size() == 1) {
std::vector<vi> as;
int i = 0;
for (i = 0; i < (int) b.size() / 2; i++) {
as.push_back(b[i]);
}
if (ask(a, as) == 1) {
assert((int) as.size() < (int) b.size());
return get2(a, as);
} else {
as.clear();
while (i < (int) b.size()) {
as.push_back(b[i++]);
}
assert((int) as.size() < (int) b.size());
return get2(a, as);
}
} else {
std::vector<vi> as;
int i = 0;
for (i = 0; i < (int) a.size() / 2; i++) {
as.push_back(a[i]);
}
if (ask(as, b) == 1) {
assert((int) as.size() < (int) a.size());
return get2(as, b);
} else {
as.clear();
while (i < (int) a.size()) {
as.push_back(a[i++]);
}
assert((int) as.size() < (int) a.size());
return get2(as, b);
}
}
};
std::vector<vi> A, B;
int sz = (int) care.size();
for (int i = 0; i < sz / 2; i++) {
A.push_back(kk[care[i]]);
}
for (int i = sz / 2; i < sz; i++) {
B.push_back(kk[care[i]]);
}
std::pair<vi, vi> res1 = get2(A, B);
// continue;
std::pair<int, int> res = get(res1.first, res1.second);
join(res.first, res.second);
setRoad(res.first, res.second);
}
}
Compilation message
icc.cpp:14: warning: "assert" redefined
14 | #define assert //assert
|
In file included from /usr/include/c++/10/cassert:44,
from icc.cpp:7:
/usr/include/assert.h:92: note: this is the location of the previous definition
92 | # define assert(expr) \
|
icc.cpp: In function 'void run(int)':
icc.cpp:115:9: warning: unused variable 'm' [-Wunused-variable]
115 | int m = n - (k - 1);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Ok! 111 queries used. |
2 |
Correct |
4 ms |
604 KB |
Ok! 120 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
604 KB |
Ok! 650 queries used. |
2 |
Correct |
35 ms |
604 KB |
Ok! 847 queries used. |
3 |
Correct |
36 ms |
692 KB |
Ok! 865 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
724 KB |
Ok! 1900 queries used. |
2 |
Correct |
143 ms |
964 KB |
Ok! 2126 queries used. |
3 |
Correct |
105 ms |
604 KB |
Ok! 2050 queries used. |
4 |
Correct |
109 ms |
748 KB |
Ok! 2051 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
106 ms |
808 KB |
Too many queries! 2043 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
119 ms |
852 KB |
Too many queries! 2085 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
796 KB |
Too many queries! 2065 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |