Submission #872414

# Submission time Handle Problem Language Result Execution time Memory
872414 2023-11-13T05:07:35 Z Muhammad_Aneeq ICC (CEOI16_icc) C++17
61 / 100
120 ms 1132 KB
#include <vector>
#include <set>
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());  
vector<int>g;
int const N=110;
vector<int>chi[N]={};int par[N]={};
bool w=0; 
bool q(vector<int>x,vector<int>y)
{
  vector<int>a,b;
  for (auto i:x)
      for (auto j:chi[i])
        a.push_back(j);
  for (auto i:y)
      for (auto j:chi[i])
        b.push_back(j);
  int* c=new int[a.size()];int *d=new int[b.size()];
  for (int i=0;i<a.size();i++)
    c[i]=a[i];
  for (int i=0;i<b.size();i++)
    d[i]=b[i];
  int z=query(a.size(),b.size(),c,d);
  return z;
}
bool q1(vector<int>a,vector<int>b)
{
  int* c=new int[a.size()];int *d=new int[b.size()];
  for (int i=0;i<a.size();i++)
    c[i]=a[i];
  for (int i=0;i<b.size();i++)
    d[i]=b[i];
  int z=query(a.size(),b.size(),c,d);
  return z;
}
bool check(int l,int r)
{
  int mid=(l+r)/2;
  vector<int>a,b;
  for (int i=l;i<=mid;i++)
     a.push_back(g[i]);
  for (int i=mid+1;i<=r;i++)
    b.push_back(g[i]);
  return q(a,b);
}
int root(int x)
{
  if (x==par[x])
    return x;
  return (par[x]=root(par[x]));
}
void merge1(int x,int y)
{
  x=root(x);
  y=root(y);
  for (auto i:chi[y])
    chi[x].push_back(i);
  chi[y]={};
  par[y]=x;
}
int DnC2(vector<int>a,vector<int>b)
{
   if (a.size()==1)
      return a[0];
    vector<int>x,y;
    int z=(a.size())/2;
    for (int i=0;i<z;i++)
      x.push_back(a[i]);
    for (int i=z;i<a.size();i++)
      y.push_back(a[i]);
    int r=q1(x,b),e=0;
    if (r==1)
      return DnC2(x,b);
    return DnC2(y,b);
}
int DnC1(vector<int>a,vector<int>b)
{
    if (a.size()==1)
      return a[0];
    vector<int>x,y;
    int z=(a.size())/2;
    for (int i=0;i<z;i++)
      x.push_back(a[i]);
    for (int i=z;i<a.size();i++)
      y.push_back(a[i]);
    int r=q1(x,b),e=0;
    if (r==1)
      return DnC1(x,b);
    return DnC1(y,b);
}
void cq1(int r,int l)
{
  vector<int>a,b;
  for (auto i:chi[r])
    a.push_back(i);
  for (auto i:chi[l])
    b.push_back(i);
  int x=DnC2(a,b);
  int y=DnC2(b,{x});
  setRoad(x,y);merge1(x,y);
}
void cq(int l,int r)
{
  int mid=(l+r)/2;
  vector<int>a,b;
  for (int i=l;i<=mid;i++)
    for (auto j:chi[g[i]])
     a.push_back(j);
  for (int i=mid+1;i<=r;i++)
    for (auto j:chi[g[i]])
     b.push_back(j);
  int x=DnC1(a,b);
  int y=DnC1(b,{x});
  setRoad(x,y);merge1(x,y);
}
void DnC(int l,int r)
{
  while (1)
  {
    shuffle(g.begin(), g.end(),RNG);
    if (check(l,r))
    {
      cq(l,r);
      break;
    }
  }
  vector<int>temp;
  for (auto i:g)
  {
    if (root(i)==i)
      temp.push_back(i);
  }
  g=temp;
}
void run(int n)
{
  for (int i=1;i<=n;i++)
  {
    par[i]=i;
    g.push_back(i);
    chi[i].push_back(i);
  }
  for (int i=0;i<n-1;i++)
  {
    w=0;
    DnC(0,g.size()-1);
  }
}

Compilation message

icc.cpp: In function 'bool q(std::vector<int>, std::vector<int>)':
icc.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int i=0;i<a.size();i++)
      |                ~^~~~~~~~~
icc.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for (int i=0;i<b.size();i++)
      |                ~^~~~~~~~~
icc.cpp: In function 'bool q1(std::vector<int>, std::vector<int>)':
icc.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i=0;i<a.size();i++)
      |                ~^~~~~~~~~
icc.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for (int i=0;i<b.size();i++)
      |                ~^~~~~~~~~
icc.cpp: In function 'int DnC2(std::vector<int>, std::vector<int>)':
icc.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i=z;i<a.size();i++)
      |                  ~^~~~~~~~~
icc.cpp:73:19: warning: unused variable 'e' [-Wunused-variable]
   73 |     int r=q1(x,b),e=0;
      |                   ^
icc.cpp: In function 'int DnC1(std::vector<int>, std::vector<int>)':
icc.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int i=z;i<a.size();i++)
      |                  ~^~~~~~~~~
icc.cpp:88:19: warning: unused variable 'e' [-Wunused-variable]
   88 |     int r=q1(x,b),e=0;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 600 KB Ok! 104 queries used.
2 Correct 6 ms 604 KB Ok! 98 queries used.
# Verdict Execution time Memory Grader output
1 Correct 22 ms 688 KB Ok! 548 queries used.
2 Correct 34 ms 752 KB Ok! 837 queries used.
3 Correct 46 ms 604 KB Ok! 833 queries used.
# Verdict Execution time Memory Grader output
1 Correct 77 ms 960 KB Ok! 1502 queries used.
2 Correct 111 ms 1132 KB Ok! 2113 queries used.
3 Correct 91 ms 916 KB Ok! 1709 queries used.
4 Correct 117 ms 852 KB Ok! 1726 queries used.
# Verdict Execution time Memory Grader output
1 Correct 80 ms 984 KB Ok! 1566 queries used.
2 Correct 89 ms 920 KB Ok! 1653 queries used.
3 Correct 120 ms 1084 KB Ok! 1836 queries used.
4 Correct 101 ms 848 KB Ok! 1625 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 1124 KB Too many queries! 1843 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 1108 KB Too many queries! 1934 out of 1625
2 Halted 0 ms 0 KB -