//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium
#include "icc.h"
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define FORN(i, n) for(int i=0;i<(n);i++)
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=acos(-1);
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
int par[101], sz[101];
void init() {
memset(par, -1, sizeof par);
for(auto&i:sz) i=1;
}
int get(int x) {
if(par[x]==-1) return x;
return par[x]=get(par[x]);
}
void merge(int x, int y) {
int px=get(x), py=get(y);
par[px]=py;
sz[py]+=sz[px];
}
int n_;
vector<int> convert(vector<int> d) {
vector<int> ans;
for(auto i:d) {
for(int j=1;j<=n_;++j) {
if(get(j)==i) ans.pb(j);
}
}
return ans;
}
bool ask(vector<int> a, vector<int> b, bool c=true) {
if(c) {
a=convert(a);
b=convert(b);
}
int A[sz(a)];
int B[sz(b)];
for(int i=0;i<sz(a);++i) A[i]=a[i];
for(int i=0;i<sz(b);++i) B[i]=b[i];
return query(sz(a), sz(b), A, B);
}
pair<int,int> bisect(vector<int> a, vector<int> b) {
if(sz(a)==1 && sz(b)==1) return {a[0], b[0]};
if(sz(a)>sz(b)) swap(a,b);
vector<int> a1,a2;
vector<int> b1,b2;
for(int i=0;i<sz(a)/2;++i) a1.pb(a[i]);
for(int i=sz(a)/2;i<sz(a);++i) a2.pb(a[i]);
for(int i=0;i<sz(b)/2;++i) b1.pb(b[i]);
for(int i=sz(b)/2;i<sz(b);++i) b2.pb(b[i]);
if(sz(a)==1) {
if(ask(a, b1, false)) return bisect(a,b1);
else return bisect(a, b2);
}
if(ask(a1,b1,false)) return bisect(a1, b1);
else if(ask(a1,b2,false)) return bisect(a1,b2);
else if(ask(a2,b1,false)) return bisect(a2, b1);
else return bisect(a2,b2);
return {-1,-1};
}
void run(int n) {
init();
n_=n;
int cnt=0;
while(cnt<n-1) {
set<int> groups;
for(int i=1;i<=n;++i) groups.insert(get(i));
vector<int> gs;
for(int i:groups) gs.pb(i);
pair<int,int> el;
for(int i=0;i<=log2(sz(gs));++i) {
vector<int> ga,gb;
for(int j=0;j<sz(gs);++j) {
if(j&(1<<i)) ga.pb(gs[j]);
else gb.pb(gs[j]);
}
if(ask(ga, gb)) {
// cerr<<"ok\n";
el=bisect(convert(ga), convert(gb));
break ;
}
}
// cerr<<el.xx<<" "<<el.yy<<"\n";
setRoad(el.xx, el.yy);
merge(el.xx, el.yy);
cnt++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
504 KB |
Ok! 123 queries used. |
2 |
Correct |
10 ms |
616 KB |
Ok! 126 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
684 KB |
Ok! 698 queries used. |
2 |
Correct |
65 ms |
704 KB |
Ok! 836 queries used. |
3 |
Correct |
77 ms |
740 KB |
Ok! 815 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
740 KB |
Ok! 1813 queries used. |
2 |
Correct |
204 ms |
744 KB |
Ok! 2117 queries used. |
3 |
Correct |
172 ms |
744 KB |
Ok! 1876 queries used. |
4 |
Correct |
175 ms |
744 KB |
Ok! 1859 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
768 KB |
Ok! 1849 queries used. |
2 |
Correct |
230 ms |
832 KB |
Ok! 1814 queries used. |
3 |
Correct |
205 ms |
832 KB |
Ok! 1996 queries used. |
4 |
Correct |
194 ms |
844 KB |
Ok! 1776 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
188 ms |
904 KB |
Too many queries! 2002 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
213 ms |
904 KB |
Too many queries! 2024 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |