#include "icc.h"
#include <iostream>
#include <vector>
#include <random>
#include <tuple>
#include <ctime>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i=0; i<(n); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
mt19937 mt_rand(time(NULL));
int query(vector<int> a, vector<int> b) {
//cout<<"query({";for(int x:a)cout<<x<<",";cout<<"}, {";for(int x:b)cout<<x<<",";cout<<"})\n";
int ar[100] = {}, br[100] = {};
rep(i, a.size()) ar[i] = a[i]+1;
rep(i, b.size()) br[i] = b[i]+1;
return query(a.size(), b.size(), ar, br);
}
int N;
int U[100];
vector<int> R[100];
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
U[y] = x;
for (int t : R[y]) R[x].pb(t);
R[y].clear();
}
vector<int> roots() {
vector<int> ret;
rep(i, N) if (find(i) == i) ret.pb(i);
return ret;
}
pair<vector<int>, vector<int>> divide2() {
vector<int> vs = roots();
int n = vs.size();
set<pair<vector<int>, vector<int>>> used;
while (true) {
shuffle(all(vs), mt_rand);
vector<int> a, b;
rep(i, n) {
if (i < n/2) for (int x : R[vs[i]]) a.pb(x);
else for (int x : R[vs[i]]) b.pb(x);
}
sort(all(a));
sort(all(b));
if (used.find(make_pair(a, b)) != used.end()) continue;
used.insert(make_pair(a, b));
if (query(a, b)) return make_pair(a, b);
}
}
int find(vector<int> X, vector<int> other) {
if (X.size() == 1) return X[0];
vector<int> a, b;
int n = X.size();
rep(i, n) {
if (i < n/2) a.pb(X[i]);
else b.pb(X[i]);
}
if (query(a, other)) return find(a, other);
else return find(b, other);
}
void run(int n) {
N = n;
rep(i, N) U[i] = i, R[i].pb(i);
rep(_, N-1) {
vector<int> a, b;
tie(a, b) = divide2();
int u = find(a, b), v = find(b, a);
//cout<<u<<"<->"<<v<<"\n";
setRoad(u+1, v+1);
unite(u, v);
}
}
Compilation message
icc.cpp: In function 'int query(std::vector<int>, std::vector<int>)':
icc.cpp:9:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
icc.cpp:19:3: note: in expansion of macro 'rep'
rep(i, a.size()) ar[i] = a[i]+1;
^
icc.cpp:9:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
icc.cpp:20:3: note: in expansion of macro 'rep'
rep(i, b.size()) br[i] = b[i]+1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2100 KB |
Ok! 93 queries used. |
2 |
Correct |
6 ms |
2100 KB |
Ok! 105 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
2232 KB |
Ok! 550 queries used. |
2 |
Correct |
59 ms |
2236 KB |
Ok! 827 queries used. |
3 |
Correct |
59 ms |
2232 KB |
Ok! 840 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
2232 KB |
Ok! 1551 queries used. |
2 |
Correct |
216 ms |
2232 KB |
Ok! 2135 queries used. |
3 |
Correct |
166 ms |
2236 KB |
Ok! 1676 queries used. |
4 |
Correct |
166 ms |
2228 KB |
Ok! 1725 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
2236 KB |
Ok! 1662 queries used. |
2 |
Correct |
163 ms |
2236 KB |
Ok! 1729 queries used. |
3 |
Correct |
186 ms |
2232 KB |
Ok! 1855 queries used. |
4 |
Correct |
179 ms |
2232 KB |
Ok! 1638 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
196 ms |
2232 KB |
Too many queries! 1897 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
179 ms |
2232 KB |
Too many queries! 1935 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |