# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
605186 |
2022-07-25T13:43:03 Z |
thezomb1e |
ICC (CEOI16_icc) |
C++17 |
|
167 ms |
492 KB |
#include "icc.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set
void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
unsyncIO(); setPrec();
if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}
struct DSU {
vector<int> e;
DSU(int n) : e(n + 5, -1) {}
int get(int x) {return e[x] <= -1 ? x : e[x] = get(e[x]);}
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x == y) return false;
if (-e[x] < -e[y]) swap(x, y);
e[x] += e[y]; e[y] = x;
return true;
}
};
bool ask(vector<int> &l, vector<int> &r) {
int sz_left = l.size(), sz_right = r.size();
int left[sz_left], right[sz_right];
for (int i = 0; i < sz_left; i++) {
left[i] = l[i];
}
for (int i = 0; i < sz_right; i++) {
right[i] = r[i];
}
return query(sz_left, sz_right, left, right);
}
void run(int n) {
DSU dsu(n + 5);
for(int _i = 0; _i < n - 1; _i++) {
vector<vector<int>> comps;
for (int i = 1; i <= n; i++) {
vector<int> cur;
for (int j = 1; j <= n; j++) {
if (dsu.get(j) == i) {
cur.pb(j);
}
}
if (!cur.empty()) {
comps.pb(cur);
}
}
bool ok = false;
vector<int> left, right;
while (!ok) {
random_shuffle(all(comps));
left.clear(); right.clear();
int c_size = comps.size();
for (int i = 0; i < c_size / 2; i++) {
for (int x : comps[i]) {
left.pb(x);
}
}
for (int i = c_size / 2; i < c_size; i++) {
for (int x : comps[i]) {
right.pb(x);
}
}
ok = ask(left, right);
}
int u = -1, v = -1;
{
int lo = 0, hi = (int) left.size() - 1;
while (lo <= hi) {
int mi = (lo + hi) / 2;
vector<int> nw;
for (int i = 0; i <= mi; i++) {
nw.pb(left[i]);
}
if (ask(nw, right)) {
u = mi;
hi = mi - 1;
} else {
lo = mi + 1;
}
}
}
{
int lo = 0, hi = (int) right.size() - 1;
while (lo <= hi) {
int mi = (lo + hi) / 2;
vector<int> nw;
for (int i = 0; i <= mi; i++) {
nw.pb(right[i]);
}
if (ask(left, nw)) {
v = mi;
hi = mi - 1;
} else {
lo = mi + 1;
}
}
}
u = left[u];
v = right[v];
setRoad(u, v);
dsu.unite(u, v);
}
}
Compilation message
icc.cpp: In function 'void setIn(std::string)':
icc.cpp:43:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
icc.cpp: In function 'void setOut(std::string)':
icc.cpp:44:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Ok! 107 queries used. |
2 |
Correct |
5 ms |
468 KB |
Ok! 105 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
492 KB |
Ok! 540 queries used. |
2 |
Correct |
45 ms |
468 KB |
Ok! 852 queries used. |
3 |
Correct |
44 ms |
468 KB |
Ok! 837 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
484 KB |
Ok! 1507 queries used. |
2 |
Correct |
167 ms |
488 KB |
Ok! 2145 queries used. |
3 |
Correct |
122 ms |
492 KB |
Ok! 1667 queries used. |
4 |
Correct |
127 ms |
468 KB |
Ok! 1711 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
488 KB |
Ok! 1643 queries used. |
2 |
Correct |
138 ms |
484 KB |
Ok! 1666 queries used. |
3 |
Correct |
147 ms |
468 KB |
Ok! 1909 queries used. |
4 |
Correct |
123 ms |
484 KB |
Ok! 1640 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
152 ms |
468 KB |
Too many queries! 1890 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
484 KB |
Too many queries! 1904 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |