Submission #605496

# Submission time Handle Problem Language Result Execution time Memory
605496 2022-07-25T18:24:01 Z SlavicG ICC (CEOI16_icc) C++17
90 / 100
151 ms 616 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;
    dsu(int n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
    }
    int get(int a) {return p[a] = (p[a] == a ? a : get(p[a]));}
    void uni(int a, int b) {
        a = get(a);
        b = get(b);
        if(a > b) swap(a, b);
        p[a] = b;
    }
};

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;
        for(int bit = 0; (1 << bit) < n; ++bit) {
            vector<int> c1, c2;
            for(int i = 1; i <= n; ++i) {
                if((d.get(i) - 1) & (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);
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        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:37:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |         int mid = l + r >> 1;
      |                   ~~^~~
icc.cpp: In function 'void run(int)':
icc.cpp:50:13: warning: unused variable 'st' [-Wunused-variable]
   50 |         int st = -1;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 107 queries used.
2 Correct 6 ms 492 KB Ok! 108 queries used.
# Verdict Execution time Memory Grader output
1 Correct 32 ms 484 KB Ok! 548 queries used.
2 Correct 39 ms 500 KB Ok! 683 queries used.
3 Correct 38 ms 468 KB Ok! 690 queries used.
# Verdict Execution time Memory Grader output
1 Correct 110 ms 608 KB Ok! 1376 queries used.
2 Correct 134 ms 488 KB Ok! 1689 queries used.
3 Correct 129 ms 500 KB Ok! 1329 queries used.
4 Correct 118 ms 504 KB Ok! 1517 queries used.
# Verdict Execution time Memory Grader output
1 Correct 119 ms 496 KB Ok! 1438 queries used.
2 Correct 137 ms 616 KB Ok! 1459 queries used.
3 Correct 129 ms 504 KB Ok! 1643 queries used.
4 Correct 128 ms 500 KB Ok! 1379 queries used.
# Verdict Execution time Memory Grader output
1 Correct 135 ms 492 KB Ok! 1643 queries used.
2 Correct 136 ms 492 KB Ok! 1653 queries used.
3 Correct 140 ms 468 KB Ok! 1657 queries used.
4 Correct 131 ms 496 KB Ok! 1587 queries used.
5 Correct 111 ms 508 KB Ok! 1457 queries used.
6 Correct 151 ms 556 KB Ok! 1587 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 500 KB Too many queries! 1662 out of 1625
2 Halted 0 ms 0 KB -