Submission #605647

# Submission time Handle Problem Language Result Execution time Memory
605647 2022-07-25T20:59:32 Z SlavicG ICC (CEOI16_icc) C++17
90 / 100
130 ms 596 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;

/*
int query(int a, int b, int* aa, int* bb) {

}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int query(vector<int> a, vector<int> b) {
    int aa[(int)a.size()], bb[(int)b.size()];
    for(int i = 0; i < (int)a.size(); ++i) aa[i] = a[i];
    for(int i = 0; i < (int)b.size(); ++i) bb[i] = b[i];
    return query(a.size(), b.size(), aa, bb);
}
struct dsu {
    vector<int> p, s;
    dsu(int n) {
        p.resize(n);
        s.assign(n, 1);
        iota(p.begin(), p.end(), 0);
    }
    int get(int a) {return p[a] = (p[a] == a ? a : get(p[a]));}
    int sz(int a) {return s[get(a)];}
    void uni(int a, int b) {
        a = get(a);
        b = get(b);
        if(s[a] > s[b]) swap(a, b);
        p[a] = b;
        s[b] += s[a];
    }
};

int ask(vector<int> a, vector<int> b) {
    int l = 0, r = (int)a.size();
    while(l < r) {
        int mid = l + r >> 1;
        vector<int> paiu;
        for(int j = 0; j <= mid; ++j) paiu.push_back(a[j]);
        if(query(paiu, b)) {
            r = mid;
        } else l = mid + 1;
    }
    return a[r];
}

void run(int n) {
    dsu d(n + 5);
    for(int times = 0; times < n - 1; ++times) {
        int st = -1;
        vector<int> v;
        for(int i = 1; i <= n; ++i) v.push_back(d.get(i));
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> A, B;
        vector<int> bits;
        vector<int> paiu;
        for(int bit = 0; (1 << bit) < (int)v.size(); ++bit) {
            vector<int> c1, c2;
            for(int i = 1; i <= n; ++i) {
                if((lower_bound(v.begin(), v.end(), d.get(i)) - v.begin()) & (1 << bit)) c1.push_back(i);
                else c2.push_back(i);
            }
            if(c1.empty() || c2.empty()) continue;
            if(query(c1, c2)) {
                A = c1, B = c2;
                break;
            }
        }
        assert(A.size() > 0 && B.size() > 0);
        vector<pair<int, int>> aa;
        for(auto x: A) aa.push_back({d.sz(x), x});
        sort(aa.begin(), aa.end());
        A.clear();
        for(auto x: aa) A.push_back(x.second);
        aa.clear();
        for(auto x: B) aa.push_back({d.sz(x), x});
        sort(aa.begin(), aa.end());
        B.clear();
        for(auto x: aa) B.push_back(x.second);

        int ansA = ask(A, B);
        int ansB = ask(B, A);
        d.uni(ansA, ansB);
        setRoad(ansA, ansB);
    }
}

/*
int main() {
    int n; cin >> n;
    run(n);
}
*/

Compilation message

icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:40:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int mid = l + r >> 1;
      |                   ~~^~~
icc.cpp: In function 'void run(int)':
icc.cpp:53:13: warning: unused variable 'st' [-Wunused-variable]
   53 |         int st = -1;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 111 queries used.
2 Correct 5 ms 468 KB Ok! 110 queries used.
# Verdict Execution time Memory Grader output
1 Correct 30 ms 496 KB Ok! 532 queries used.
2 Correct 36 ms 468 KB Ok! 661 queries used.
3 Correct 34 ms 496 KB Ok! 646 queries used.
# Verdict Execution time Memory Grader output
1 Correct 100 ms 500 KB Ok! 1457 queries used.
2 Correct 112 ms 504 KB Ok! 1609 queries used.
3 Correct 117 ms 488 KB Ok! 1635 queries used.
4 Correct 127 ms 468 KB Ok! 1519 queries used.
# Verdict Execution time Memory Grader output
1 Correct 108 ms 500 KB Ok! 1543 queries used.
2 Correct 103 ms 500 KB Ok! 1532 queries used.
3 Correct 105 ms 488 KB Ok! 1569 queries used.
4 Correct 130 ms 508 KB Ok! 1581 queries used.
# Verdict Execution time Memory Grader output
1 Correct 114 ms 596 KB Ok! 1561 queries used.
2 Correct 114 ms 492 KB Ok! 1579 queries used.
3 Correct 113 ms 504 KB Ok! 1634 queries used.
4 Correct 104 ms 488 KB Ok! 1562 queries used.
5 Correct 112 ms 484 KB Ok! 1475 queries used.
6 Correct 118 ms 488 KB Ok! 1554 queries used.
# Verdict Execution time Memory Grader output
1 Correct 105 ms 492 KB Ok! 1577 queries used.
2 Incorrect 111 ms 468 KB Too many queries! 1626 out of 1625
3 Halted 0 ms 0 KB -