Submission #707181

# Submission time Handle Problem Language Result Execution time Memory
707181 2023-03-08T14:53:39 Z uylulu ICC (CEOI16_icc) C++17
0 / 100
9 ms 500 KB
#include<bits/stdc++.h>
#include "icc.h"   
using namespace std;

// #define endl "\n"

const int N = 100;

int a[N + 1],b[N + 1],pa[N + 1],n;

vector<int> st[N + 1];

// int query(int size_a,int size_b,int ta[],int tb[]) {
//     cout<<"?"<<endl;
//     for(int i = 0;i < size_a;i++) {
//         cout<<ta[i]<<" ";
//     }
//     cout<<endl;
//     for(int i = 0;i < size_b;i++) {
//         cout<<tb[i]<<" ";
//     }
//     cout<<endl;
//     int x;
//     cin>>x;
//     return x;
// }

// void setRoad(int a,int b) {
//     cout<<"!"<<" "<<a<<" "<<b<<endl;
//     return;
// }

int find(int a) {
    if(a == pa[a]) return a;
    return pa[a] = find(pa[a]);
}

void unite(int a,int b) {
    a = find(a);
    b = find(b);
    if(a == b) return;
    if(st[a].size() < st[b].size()) swap(a,b);

    pa[b] = a;
    for(auto u : st[b]) {
        st[a].push_back(u);
    }
}

int ask(vector<int> i1,vector<int> i2) {
    vector<int> l,r;

    for(auto u : i1) {
        if(u != find(u)) continue;

        for(auto v : st[u]) {
            l.push_back(v);
        }
    }
    for(auto u : i2) {
        if(u != find(u)) continue;

        for(auto v : st[u]) {
            r.push_back(v);
        }
    }
    for(int i = 0;i < l.size();i++) {
        a[i] = l[i];
    }
    for(int i = 0;i < r.size();i++) {
        b[i] = r[i];
    }
    return query((int)l.size(),(int)r.size(),a,b);
}

pair<int,int> cal(vector<int> le,vector<int> ri) {
    int l = 0,r = le.size(),trai = -1,phai = -1;
    vector<int> tmp;

    // cout<<"HERE"<<endl;
    // for(auto u : le) {
    //     cout<<u<<" ";
    // }
    // cout<<endl;
    // for(auto u : ri) {
    //     cout<<u<<" ";
    // }
    // cout<<endl<<endl;


    while(l < r) {
        int mid = (l + r)/2;
        tmp.clear();

        for(int i = l;i <= mid;i++) {
            tmp.push_back(le[i]);
        }
        if(ask(tmp,ri)) {
            trai = mid;
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    l = 0;
    r = ri.size();

    // cout<<"DONE"<<endl;

    while(l < r) {
        int mid = (l + r)/2;
        tmp.clear();

        for(int i = l;i <= mid;i++) {
            tmp.push_back(ri[i]);
        }
        if(ask(le,tmp)) {
            phai = mid;
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    return {le[trai],ri[phai]};
}

void process() {
    vector<int> tl,tr;

    for(int pos = 0;pos < 7;pos++) {
        tl.clear();
        tr.clear();

        for(int i = 1;i <= n;i++) {
            if(i != find(i)) continue;

            if((i >> pos) % 2 == 0) {
                tl.push_back(i);
            } else {
                tr.push_back(i);
            }
        }

        if(ask(tl,tr)) {
            vector<int> i1,i2;

            for(auto u : tl) {
                for(auto v : st[u]) {
                    i1.push_back(v);
                }
            }
            for(auto u : tr) {
                for(auto v : st[u]) {
                    i2.push_back(v);
                }
            }
            auto res = cal(i1,i2);

            setRoad(res.first,res.second);
            unite(res.first,res.second);
            break;
        }
    }

}

void run(int N) {
    n = N;
    for(int i = 1;i <= n;i++) {
        pa[i] = i;
        st[i].push_back(i);
    }
    for(int i = 1;i < n;i++) {
        process();
    }
}    

// signed main() {
//     run(4);
// }

Compilation message

icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0;i < l.size();i++) {
      |                   ~~^~~~~~~~~~
icc.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i = 0;i < r.size();i++) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 500 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -