# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
128816 |
2019-07-11T09:51:16 Z |
zubec |
ICC (CEOI16_icc) |
C++14 |
|
5 ms |
504 KB |
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
int n;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int sz1, sz2, A[110], B[110];
int my_query(vector<int> &vec1, vector <int> &vec2){
sz1 = sz2 = 0;
for (int i = 0; i < vec1.size(); i++)
A[sz1++] = vec1[i];
for (int i = 0; i < vec2.size(); i++)
B[sz2++] = vec2[i];
return query(sz1, sz2, A, B);
}
int dsu[110];
int dsu_get(int v){
if (v == dsu[v])
return v;
return dsu[v] = dsu_get(dsu[v]);
}
void dsu_unite(int a, int b){
a = dsu_get(a);
b = dsu_get(b);
dsu[b] = a;
}
vector <int> g[110];
void run(int N){
n = N;
for (int i = 1; i <= n; i++){
dsu[i] = i;
}
for (int tt = 1; tt < n; tt++){
vector <int> vec;
for (int i = 1; i <= n; i++)
g[i].clear();
for (int i = 1; i <= n; i++){
vec.push_back(dsu_get(i));
g[dsu_get(i)].push_back(i);
}
vec.erase(unique(vec.begin(), vec.end()), vec.end());
while(1){
shuffle(vec.begin(), vec.end(), rnd);
int pos = vec.size()/2-1;
vector <int> vec1, vec2;
for (int j = 0; j <= pos; j++){
for (int l = 0; l < g[vec[j]].size(); l++)
vec1.push_back(g[vec[j]][l]);
}
for (int j = pos+1; j < vec.size(); j++){
for (int l = 0; l < g[vec[j]].size(); l++)
vec2.push_back(g[vec[j]][l]);
}
if (!my_query(vec1, vec2))
continue;
int l = 0, r = vec1.size()-1;
while(l < r){
int mid = (l+r)>>1;
vector <int> cur;
for (int j = l; j <= mid; j++)
cur.push_back(vec1[j]);
if (my_query(cur, vec2))
r = mid; else
l = mid+1;
}
int a = vec1[l];
l = 0, r = vec2.size();
while(l < r){
int mid = (l+r)>>1;
vector <int> cur;
for (int j = l; j <= mid; j++)
cur.push_back(vec2[j]);
if (my_query(vec1, cur))
r = mid; else
l = mid+1;
}
int b = vec2[l];
setRoad(a, b);
dsu_unite(a, b);
break;
}
}
}
/**
5
1 2
1 3
1 4
1 5
*/
Compilation message
icc.cpp: In function 'int my_query(std::vector<int>&, std::vector<int>&)':
icc.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vec1.size(); i++)
~~^~~~~~~~~~~~~
icc.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vec2.size(); i++)
~~^~~~~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:56:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int l = 0; l < g[vec[j]].size(); l++)
~~^~~~~~~~~~~~~~~~~~
icc.cpp:59:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = pos+1; j < vec.size(); j++){
~~^~~~~~~~~~~~
icc.cpp:60:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int l = 0; l < g[vec[j]].size(); l++)
~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
500 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
504 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |