#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
typedef pair<int,int> ii;
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
#define ff first
#define ss second
int n, p[105], a[105], b[105];
vector <int> adj[105], parents;
void divide(vector <ii> v1, vector <ii> v2, vector <ii> &a1, vector <ii> &a2){
for(auto p: v1){
int l = p.ff, r = p.ss, sz = r-l+1;
if(sz > 1) a1.push_back({l, l+(sz/2)-1}), a2.push_back({l+(sz/2), r});
else a1.push_back({l, r});
}
for(auto p: v2){
int l = p.ff, r = p.ss, sz = r-l+1;
if(sz > 1) a1.push_back({l, l+(sz/2)-1}), a2.push_back({l+(sz/2), r});
else a1.push_back({l, r});
}
}
vector <int> get(vector <ii> v){
vector <int> ra;
for(auto p: v){
int l = p.ff, r = p.ss;
f(i,l,r+1) for(int x: adj[parents[i]]) ra.push_back(x);
}
return ra;
}
bool Q(int x, int y, vector <int> ra, vector <int> ta){
f(i,0,x) a[i] = ra[i];
f(i,0,y) b[i] = ta[i];
return query(x, y, a, b);
}
void run(int x){
n = x;
f(i,1,n+1) adj[i] = {i}, p[i] = i;
f(ra,1,n){
parents.clear(); vector <ii> v1, v2; vector <int> V1, V2;
f(i,1,n+1) if(adj[i].size()) parents.push_back(i);
int sz = parents.size();
v1 = {{0, sz-1}};
while(1){
vector <ii> aux1, aux2;
divide(v1, v2, aux1, aux2);
v1 = aux1, v2 = aux2;
V1 = get(v1), V2 = get(v2);
if(Q(V1.size(), V2.size(), V1, V2)) break;
}
while(V1.size() > 1){
int s = V1.size();
vector <int> ra, ta;
f(i,0,s/2) ra.push_back(V1[i]); f(i,s/2,s) ta.push_back(V1[i]);
int e = rand()%2;
if(e == 1){
if(Q(V2.size(), ra.size(), V2, ra)) V1 = ra;
else V1 = ta;
}
else{
if(Q(V2.size(), ta.size(), V2, ta)) V1 = ta;
else V1 = ra;
}
}
while(V2.size() > 1){
int s = V2.size();
vector <int> ra, ta;
f(i,0,s/2) ra.push_back(V2[i]); f(i,s/2,s) ta.push_back(V2[i]);
int e = rand()%2;
if(e == 1){
if(Q(V1.size(), ra.size(), V1, ra)) V2 = ra;
else V2 = ta;
}
else{
if(Q(V1.size(), ta.size(), V1, ta)) V2 = ta;
else V2 = ra;
}
}
int x = V1[0], y = V2[0];
setRoad(x, y);
x = p[x], y = p[y];
for(int wi: adj[x]) p[wi] = y, adj[y].push_back(wi);
adj[x].clear();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Ok! 110 queries used. |
2 |
Correct |
5 ms |
460 KB |
Ok! 106 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
492 KB |
Ok! 552 queries used. |
2 |
Correct |
34 ms |
460 KB |
Ok! 680 queries used. |
3 |
Correct |
36 ms |
480 KB |
Ok! 681 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
488 KB |
Ok! 1500 queries used. |
2 |
Correct |
117 ms |
488 KB |
Ok! 1655 queries used. |
3 |
Correct |
107 ms |
492 KB |
Ok! 1601 queries used. |
4 |
Correct |
114 ms |
484 KB |
Ok! 1531 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
516 KB |
Ok! 1607 queries used. |
2 |
Correct |
112 ms |
484 KB |
Ok! 1601 queries used. |
3 |
Correct |
112 ms |
460 KB |
Ok! 1677 queries used. |
4 |
Correct |
107 ms |
488 KB |
Ok! 1550 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
496 KB |
Ok! 1650 queries used. |
2 |
Correct |
127 ms |
488 KB |
Ok! 1637 queries used. |
3 |
Correct |
136 ms |
512 KB |
Ok! 1687 queries used. |
4 |
Correct |
116 ms |
460 KB |
Ok! 1669 queries used. |
5 |
Correct |
101 ms |
484 KB |
Ok! 1533 queries used. |
6 |
Correct |
124 ms |
488 KB |
Ok! 1589 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
492 KB |
Too many queries! 1666 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |