답안 #872417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872417 2023-11-13T05:11:17 Z Faisal_Saqib CEOI16_icc (CEOI16_icc) C++17
90 / 100
114 ms 640 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
#define vll vector<int>
const int N=200;
int par[N];
int sz[N];
void init(int n)
{
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        sz[i]=1;
    }
}
int root(int x)
{
    return (par[x]==x?x:par[x]=root(par[x]));
}
void join(int x,int y)
{
    x=root(x);
    y=root(y);
    if(x!=y)
    {
        par[x]=y;
        sz[y]+=sz[x];
    }
}
int n_n_n;
vll modify(vll& a)
{
  vll b;
  for(auto i:a)
    for(int j=1;j<=n_n_n;j++)
      if(root(j)==i)
        b.push_back(j);
  return b;
}
int check_edge(vll& a,vll& b)
{
    if(a.size()==0 or b.size()==0)
    {
        return 0;
    }
  int n=a.size();
  int m=b.size();
  int a_[n];
  for(int i=0;i<n;i++)
    a_[i]=a[i];
  int b_[m];
  for(int i=0;i<m;i++)
    b_[i]=b[i];
  return query(n,m,a_,b_);
}
vll fit,sed;
int fix_first(int l,int r)
{
  if(l==r)
    return l;
  int mid=(l+r)/2;
  vll cur;
  for(int i=l;i<=mid;i++)
    cur.push_back(fit[i]);
  if(check_edge(cur,sed))
    return fix_first(l,mid);
  else
    return fix_first(mid+1,r);
}
void between(vll& a,vll& b)
{
  fit=a;
  sed=b;
  int ind=fix_first(0,((int)a.size())-1);
  // cout<<"Hello "<<' '<<ind<<' '<<a[ind]<<endl;
  fit={fit[ind]};
  swap(sed,fit);
  ind=fix_first(0,((int)b.size())-1);
  // cout<<"Hello "<<' '<<ind<<' '<<b[ind]<<endl;
  fit={fit[ind]};
}
bool found_=0;
void solve(vll& big)
{
    int mos=big.back();
    int lg=log2(mos);
    vll bits;
    for(int j=0;j<=lg;j++)
    {
      bits.push_back(j);
    }
    random_shuffle(begin(bits),end(bits));
    for(auto j:bits)
    {
        vll a,b;
        for(auto i:big)
        {
            if((1ll<<j)&i)
            {
                a.push_back(i);
            }
            else
            {
                b.push_back(i);
            }
        }
        vll c=modify(a),d=modify(b);
        if(check_edge(c,d))
        {
            between(c,d);
            return;
        }
    }
}
void run(int n)
{
  n_n_n=n;
  init(n);
  int q=n-1;
  while(q--)
  {
    // cout<<"Add edge \n";
    // int x_,y_;
    // cin>>x_>>y_;
    // ka[x_][y_]=1;
    // ka[y_][x_]=1;
    vll big;
    for(int i=1;i<=n;i++)
      if(par[i]==i)
        big.push_back(i);
    // for(auto i:big)
    // {
    //   cout<<i<<' ';
    // }
    // cout<<endl;
    // cout<<"HEllo "<<check_edge(a,b)<<endl;;
    found_=0;
    solve(big);
    // cout<<"edge is "<<fit[0]<<' '<<sed[0]<<endl;
    join(fit[0],sed[0]);
    setRoad(fit[0],sed[0]);
    // break;
  }
}
// int main()
// {
//   int n;
//   cin>>n;  
//   run(n);
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 600 KB Ok! 103 queries used.
2 Correct 4 ms 604 KB Ok! 103 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 604 KB Ok! 549 queries used.
2 Correct 30 ms 636 KB Ok! 709 queries used.
3 Correct 28 ms 604 KB Ok! 666 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 604 KB Ok! 1358 queries used.
2 Correct 114 ms 616 KB Ok! 1772 queries used.
3 Correct 81 ms 604 KB Ok! 1451 queries used.
4 Correct 85 ms 640 KB Ok! 1512 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 616 KB Ok! 1491 queries used.
2 Correct 81 ms 636 KB Ok! 1474 queries used.
3 Correct 87 ms 624 KB Ok! 1559 queries used.
4 Correct 75 ms 600 KB Ok! 1405 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 600 KB Ok! 1581 queries used.
2 Correct 91 ms 600 KB Ok! 1626 queries used.
3 Correct 93 ms 616 KB Ok! 1656 queries used.
4 Correct 90 ms 600 KB Ok! 1598 queries used.
5 Correct 80 ms 604 KB Ok! 1461 queries used.
6 Correct 94 ms 600 KB Ok! 1626 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 628 KB Too many queries! 1641 out of 1625
2 Halted 0 ms 0 KB -