# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
23380 |
2017-05-08T05:18:34 Z |
rubabredwan |
ICC (CEOI16_icc) |
C++14 |
|
146 ms |
2276 KB |
/* Bismillahir Rahmanir Rahim */
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> fii;
const int N = 105;
int n, par[N], mat[N][N];
set<int>comp;
vector<int>nudes[N];
int Find(int at){
return par[at] == at ? at : par[at] = Find(par[at]);
}
void Union(int a, int b){
int x = Find(a);
int y = Find(b);
for(auto u : nudes[y]){
nudes[x].push_back(u);
}
par[y] = x;
comp.erase(y);
}
/* void setRoad(int a, int b){ */
/* if(a) Union(a, b); */
/* int x, y; */
/* cin >> x >> y; */
/* mat[x][y] = 1; */
/* mat[y][x] = 1; */
/* } */
/* int query(int sa, int sb, int a[], int b[]){ */
/* for(int i=0;i<sa;i++){ */
/* for(int j=0;j<sb;j++){ */
/* if(mat[a[i]][b[j]]) return true; */
/* } */
/* } */
/* return false; */
/* } */
int bs[N], tt;
int get(int sa, int sb, int a[], int b[]){
int lo = 0, hi = sb - 1;
while(lo < hi){
int mid = (lo + hi) / 2; tt = 0;
for(int i=lo;i<=mid;i++) bs[tt] = b[i], ++tt;
if(query(sa, tt, a, bs)) hi = mid;
else lo = mid + 1;
}
return b[lo];
}
int aa[N], bb[N];
int sa, sb;
vector<int>vv[10][2];
void run(int _n){
srand(time(NULL));
n = _n;
comp.clear();
for(int i=1;i<=n;i++){
par[i] = i;
comp.insert(i);
nudes[i].push_back(i);
}
int road = n - 1;
while(road--){
int f1 = 0, f2 = 0;
vector<fii>F;
for(int bit=7;bit>=0;bit--){
vv[bit][0].clear();
vv[bit][1].clear();
for(auto u : comp){
if(u & (1 << bit)) for(auto v : nudes[u]) vv[bit][0].push_back(v);
else for(auto v : nudes[u]) vv[bit][1].push_back(v);
}
if(vv[bit][0].size() == 0) continue;
if(vv[bit][1].size() == 0) continue;
if(query(vv[bit][0].size(), vv[bit][1].size(), vv[bit][0].data(), vv[bit][1].data())){
F.push_back({{vv[bit][0].size(), bit}, 0});
F.push_back({{vv[bit][1].size(), bit}, 1});
break;
}
}
sort(F.begin(), F.end());
for(auto u : F){
int b = u.first.second, t = u.second;
if(find(vv[b][t].begin(), vv[b][t].end(), f1) != vv[b][t].end()) continue;
if(find(vv[b][t].begin(), vv[b][t].end(), f2) != vv[b][t].end()) continue;
if(!f1){
f1 = get(vv[b][t^1].size(), vv[b][t].size(), vv[b][t^1].data(), vv[b][t].data());
}
else if(!f2){
f2 = get(vv[b][t^1].size(), vv[b][t].size(), vv[b][t^1].data(), vv[b][t].data());
}
}
assert(f1);
assert(f2);
Union(f1, f2);
setRoad(f1, f2);
}
}
/* int main(){ */
/* int ff, x, y; */
/* scanf("%d", &ff); */
/* setRoad(0, 0); */
/* run(ff); */
/* return 0; */
/* } */
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2136 KB |
Ok! 96 queries used. |
2 |
Correct |
6 ms |
2140 KB |
Ok! 102 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2268 KB |
Ok! 538 queries used. |
2 |
Correct |
46 ms |
2136 KB |
Ok! 703 queries used. |
3 |
Correct |
46 ms |
2136 KB |
Ok! 697 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
2272 KB |
Ok! 1486 queries used. |
2 |
Correct |
143 ms |
2276 KB |
Ok! 1733 queries used. |
3 |
Correct |
113 ms |
2268 KB |
Ok! 1426 queries used. |
4 |
Correct |
133 ms |
2268 KB |
Ok! 1597 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
2272 KB |
Ok! 1464 queries used. |
2 |
Correct |
123 ms |
2268 KB |
Ok! 1517 queries used. |
3 |
Correct |
136 ms |
2272 KB |
Ok! 1672 queries used. |
4 |
Correct |
116 ms |
2276 KB |
Ok! 1451 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
2268 KB |
Ok! 1681 queries used. |
2 |
Correct |
143 ms |
2276 KB |
Ok! 1706 queries used. |
3 |
Correct |
139 ms |
2268 KB |
Ok! 1700 queries used. |
4 |
Correct |
136 ms |
2268 KB |
Ok! 1649 queries used. |
5 |
Correct |
126 ms |
2268 KB |
Ok! 1530 queries used. |
6 |
Correct |
146 ms |
2272 KB |
Ok! 1626 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
2268 KB |
Too many queries! 1684 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |