Submission #116674

# Submission time Handle Problem Language Result Execution time Memory
116674 2019-06-13T14:07:04 Z IOrtroiii ICC (CEOI16_icc) C++14
90 / 100
197 ms 728 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

const int N = 105;

int qa[N], qb[N];

int query(vector<int> a, vector<int> b) {
   int sza = a.size(), szb = b.size();
   for (int i = 0; i < sza; ++i) {
      qa[i] = a[i];
   }
   for (int i = 0; i < szb; ++i) {
      qb[i] = b[i];
   }
   return query(sza, szb, qa, qb);
}

int fnd(int l, int r, vector<int> &from, vector<int> &to) {
   if (l == r) { return from[l]; }
   int md = (l + r) >> 1;
   vector<int> ll;
   for (int i = l; i <= md; ++i) {
      ll.push_back(from[i]);
   }
   if (query(ll, to)) {
      return fnd(l, md, from, to);
   } else {
      return fnd(md + 1, r, from, to);
   }
}

int p[N];
vector<int> comp[N];

int getp(int u) {
   if (p[u] == u) {
      return u;
   } else {
      return p[u] = getp(p[u]);
   }
}

void mrg(int u, int v) {
   u = getp(u), v = getp(v);
   if (comp[u].size() < comp[v].size()) {
      swap(u, v);
   }
   p[v] = u;
   for (int w : comp[v]) {
      comp[u].push_back(w);
   }
}

void modify(vector<int> l, vector<int> r) {
   int u = fnd(0, l.size(), l, r);
   int v = fnd(0, r.size(), r, l);
   mrg(u, v);
   setRoad(u, v);
}

int n;

void solve() {
   vector<int> roots;
   for (int i = 1; i <= n; ++i) {
      if (p[i] == i) {
         roots.push_back(i);
      }
   }
   for (int i = 0; (1 << i) < roots.size(); ++i) {
      vector<int> l, r;
      for (int j = 0; j < roots.size(); ++j) {
         if (j & (1 << i)) {
            for (int v : comp[roots[j]]) {
               l.push_back(v);
            }
         } else {
            for (int v : comp[roots[j]]) {
               r.push_back(v);
            }
         }
      }
      if (query(l, r)) {
         modify(l, r);
         return;
      }
   }
}

void run(int n) {
   ::n = n;
   for (int i = 1; i <= n; ++i) {
      p[i] = i;
      comp[i].push_back(i);
   }
   for (int i = 0; i < n - 1; ++i) {
      solve();
   }
}

Compilation message

icc.cpp: In function 'void solve()':
icc.cpp:72:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; (1 << i) < roots.size(); ++i) {
                    ~~~~~~~~~^~~~~~~~~~~~~~
icc.cpp:74:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < roots.size(); ++j) {
                       ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Ok! 104 queries used.
2 Correct 8 ms 512 KB Ok! 109 queries used.
# Verdict Execution time Memory Grader output
1 Correct 35 ms 632 KB Ok! 545 queries used.
2 Correct 43 ms 512 KB Ok! 669 queries used.
3 Correct 47 ms 512 KB Ok! 672 queries used.
# Verdict Execution time Memory Grader output
1 Correct 121 ms 560 KB Ok! 1440 queries used.
2 Correct 197 ms 576 KB Ok! 1647 queries used.
3 Correct 122 ms 568 KB Ok! 1597 queries used.
4 Correct 124 ms 728 KB Ok! 1533 queries used.
# Verdict Execution time Memory Grader output
1 Correct 120 ms 512 KB Ok! 1588 queries used.
2 Correct 124 ms 604 KB Ok! 1552 queries used.
3 Correct 124 ms 600 KB Ok! 1643 queries used.
4 Correct 123 ms 512 KB Ok! 1533 queries used.
# Verdict Execution time Memory Grader output
1 Correct 127 ms 512 KB Ok! 1651 queries used.
2 Correct 125 ms 564 KB Ok! 1643 queries used.
3 Correct 127 ms 512 KB Ok! 1643 queries used.
4 Correct 123 ms 512 KB Ok! 1653 queries used.
5 Correct 118 ms 596 KB Ok! 1404 queries used.
6 Correct 130 ms 512 KB Ok! 1542 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 632 KB Too many queries! 1672 out of 1625
2 Halted 0 ms 0 KB -