Submission #368222

# Submission time Handle Problem Language Result Execution time Memory
368222 2021-02-19T19:24:41 Z ivan_tudor ICC (CEOI16_icc) C++14
100 / 100
227 ms 724 KB
#include"icc.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int dad[N];
vector<int> memb[N];
int findd(int nod){
  if(nod == dad[nod])
    return nod;
  int d = findd(dad[nod]);
  dad[nod] = d;
  return dad[nod];
}
void join(int x,int y){
  x = findd(x);
  y = findd(y);
  if(x == y)
    return;
  if(memb[x].size() < memb[y].size()){
    swap(x, y);
    swap(memb[x], memb[y]);
  }
  for(auto mm:memb[y]){
    memb[x].push_back(mm);
  }
  dad[y] = x;
}
int used[N];
void buildgroups(vector<int> &gra, vector<int> &grb, vector<int> &dads, int bit){
  for(int i =0; i<dads.size();i++){
    if(i & ( 1<<bit)){
      for(auto x:memb[dads[i]])
        gra.push_back(x);
    }
    else{
      for(auto x:memb[dads[i]])
        grb.push_back(x);
    }
  }
}
int findx(vector<int> v, vector<int> second){
  vector<int> nou;
  while(v.size() > 1){
    int mid = (v.size() -1 )/2;
    nou.clear();
    for(int i = 0; i<=mid;i++)
      nou.push_back(v[i]);
    if(query(nou.size(), second.size(), nou.data(), second.data()))
      v = nou;
    else
      v.erase(v.begin(), v.begin() + mid + 1);
  }
  assert(!v.empty());
  return v[0];
}
void run(int n){
  for(int i=1;i<=n;i++)
    dad[i] = i, memb[i].push_back(i);
  for(int nre = 1; nre<n;nre++){
    for(int i=1;i<=n;i++)
      used[i] = 0;
    vector<int> dads;
    for(int i = 1; i<=n;i++){
      int tata = findd(i);
      if(used[tata] == true)
        continue;
      used[tata] = true;
      dads.push_back(tata);
    }
    int ds = dads.size();
    vector<int> gra, grb;
    for(int bit = 0; (1<<bit) < ds; bit++){
      gra.clear();
      grb.clear();
      buildgroups(gra, grb, dads, bit);
      if(query(gra.size(), grb.size(), gra.data(), grb.data()) == 1){
        int x, y;
        x = findx(gra, grb);
        y = findx(grb, gra);
        setRoad(x, y);
        join(x, y);
        break;
      }
    }
  }

}

Compilation message

icc.cpp: In function 'void buildgroups(std::vector<int>&, std::vector<int>&, std::vector<int>&, int)':
icc.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i =0; i<dads.size();i++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 492 KB Ok! 95 queries used.
2 Correct 7 ms 492 KB Ok! 98 queries used.
# Verdict Execution time Memory Grader output
1 Correct 56 ms 580 KB Ok! 526 queries used.
2 Correct 64 ms 576 KB Ok! 653 queries used.
3 Correct 61 ms 492 KB Ok! 636 queries used.
# Verdict Execution time Memory Grader output
1 Correct 144 ms 576 KB Ok! 1379 queries used.
2 Correct 177 ms 492 KB Ok! 1593 queries used.
3 Correct 173 ms 620 KB Ok! 1593 queries used.
4 Correct 180 ms 620 KB Ok! 1481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 141 ms 620 KB Ok! 1424 queries used.
2 Correct 153 ms 620 KB Ok! 1452 queries used.
3 Correct 161 ms 492 KB Ok! 1575 queries used.
4 Correct 186 ms 596 KB Ok! 1493 queries used.
# Verdict Execution time Memory Grader output
1 Correct 227 ms 576 KB Ok! 1540 queries used.
2 Correct 161 ms 716 KB Ok! 1515 queries used.
3 Correct 178 ms 724 KB Ok! 1573 queries used.
4 Correct 159 ms 584 KB Ok! 1525 queries used.
5 Correct 182 ms 580 KB Ok! 1442 queries used.
6 Correct 147 ms 584 KB Ok! 1478 queries used.
# Verdict Execution time Memory Grader output
1 Correct 157 ms 576 KB Ok! 1538 queries used.
2 Correct 211 ms 580 KB Ok! 1588 queries used.