# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
141112 |
2019-08-06T18:42:56 Z |
shayan_p |
ICC (CEOI16_icc) |
C++14 |
|
138 ms |
632 KB |
// only miss the sun when it starts to snow
#include<bits/stdc++.h>
#include "icc.h"
#define unit icc
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=110,mod=1e9+7;
const ll inf=1e18;
int bos[maxn], n;
vector<int> v[maxn], A, B, vec, vec0, vec1;
int arr1[maxn], arr2[maxn];
bool ask(){
if(sz(A)==0 || sz(B)==0) return 0;
int N=sz(A), M=sz(B);
for(int i=0;i<N;i++)
arr1[i]= A[i]+1;
for(int i=0;i<M;i++)
arr2[i]= B[i]+1;
return query(N,M,arr1,arr2);
}
void operator += (vector<int>&a,vector<int>&b){
for(int x:b) a.PB(x);
}
void Merge(int a,int b){
a=bos[a], b=bos[b];
if(sz(v[a]) < sz(v[b])) swap(a,b);
for(int x:v[b]) bos[x]=a, v[a].PB(x);
v[b].clear();
}
int solve(vector<int> &v1, vector<int>&v2){
int bt=32-__builtin_clz(sz(v1));
B=v2;
int ans=0;
for(int i=0;i<bt;i++){
A.clear();
for(int j=0;j<sz(v1);j++)
if(bit(j,i)) A.PB(v1[j]);
if(ask()) ans^=(1<<i);
}
return v1[ans];
}
void proc(){
vec.clear();
for(int i=0;i<n;i++){
if(bos[i]==i) vec.PB(i);
}
int bt=32-__builtin_clz(sz(vec));
int df=-1, bts=0;
for(int i=0;i<bt;i++){
A.clear(), B.clear();
for(int j=0;j<sz(vec);j++){
if(bit(j,i)) A+= v[vec[j]];
else B+= v[vec[j]];
}
if(ask()){
df=i;
break;
}
else{
bts^=(1<<i);
}
}
assert(df!=-1);
vec0=A, vec1=B;
int u=solve(vec0,vec1);
vec0.clear(), vec0.PB(u);
vec1.clear();
int id=-1;
for(int i=0;i<sz(vec);i++){
if(vec[i] == bos[u]) id=i;
}
assert(id!=-1);
for(int i=0;i<sz(vec);i++){
if(bit(i,df)) continue;
for(int j=0;j<bt;j++){
if(bit(bts,j) && bit(i,j)!=bit(id,j)) goto Hell;
}
vec1+= v[vec[i]];
Hell:;
}
int v=solve(vec1,vec0);
setRoad(u+1,v+1), Merge(u,v);
}
void run(int N){
::n=N;
for(int i=0;i<n;i++)
bos[i]=i, v[i].PB(i);
for(int i=0;i<n-1;i++)
proc();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Ok! 96 queries used. |
2 |
Correct |
8 ms |
504 KB |
Ok! 99 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
504 KB |
Ok! 535 queries used. |
2 |
Correct |
39 ms |
504 KB |
Ok! 492 queries used. |
3 |
Correct |
42 ms |
504 KB |
Ok! 525 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
572 KB |
Ok! 1337 queries used. |
2 |
Correct |
128 ms |
504 KB |
Ok! 1221 queries used. |
3 |
Correct |
132 ms |
504 KB |
Ok! 1416 queries used. |
4 |
Correct |
137 ms |
504 KB |
Ok! 1433 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
604 KB |
Ok! 1423 queries used. |
2 |
Correct |
133 ms |
568 KB |
Ok! 1322 queries used. |
3 |
Correct |
136 ms |
604 KB |
Ok! 1410 queries used. |
4 |
Correct |
130 ms |
508 KB |
Ok! 1313 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
504 KB |
Ok! 1232 queries used. |
2 |
Correct |
135 ms |
572 KB |
Ok! 1337 queries used. |
3 |
Correct |
133 ms |
492 KB |
Ok! 1329 queries used. |
4 |
Correct |
133 ms |
504 KB |
Ok! 1347 queries used. |
5 |
Correct |
138 ms |
504 KB |
Ok! 1389 queries used. |
6 |
Correct |
135 ms |
504 KB |
Ok! 1376 queries used. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
632 KB |
Ok! 1384 queries used. |
2 |
Correct |
131 ms |
572 KB |
Ok! 1272 queries used. |