Submission #467546

# Submission time Handle Problem Language Result Execution time Memory
467546 2021-08-23T14:39:56 Z Bench0310 ICC (CEOI16_icc) C++17
100 / 100
144 ms 612 KB
#include <bits/stdc++.h>
#include "icc.h"

using namespace std;
typedef long long ll;

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

int q(vector<int> a,vector<int> b)
{
    int sa=a.size();
    int sb=b.size();
    int x[sa];
    for(int i=0;i<sa;i++) x[i]=a[i];
    int y[sb];
    for(int i=0;i<sb;i++) y[i]=b[i];
//    cout << "? [ ";
//    for(int t:a) cout << t << " ";
//    cout << "] [ ";
//    for(int t:b) cout << t << " ";
//    cout << "]" << endl;
//    int r;
//    cin >> r;
//    return r;
    return query(sa,sb,x,y);
}

void run(int n)
{
    vector<vector<int>> v;
    for(int i=1;i<=n;i++) v.push_back({i});
    while(v.size()>1)
    {
        int cc=v.size();
        vector<int> id(n+1,-1);
        for(int i=0;i<cc;i++) for(int x:v[i]) id[x]=i;
        auto split=[&](int b)->array<vector<int>,2>
        {
            vector<int> one,two;
            for(int j=0;j<cc;j++)
            {
                if(j&(1<<b)) one.insert(one.end(),v[j].begin(),v[j].end());
                else two.insert(two.end(),v[j].begin(),v[j].end());
            }
            return {one,two};
        };
        int b=0;
        while(cc>>(b+1)) b++;
        for(int i=0;i<b;i++)
        {
            auto [one,two]=split(i);
            if(q(one,two)==1)
            {
                b=i;
                break;
            }
        }
        auto [one,two]=split(b);
        if(one.size()>two.size()) swap(one,two);
        auto go=[&](vector<int> x,vector<int> y)->int
        {
            int l=0,r=x.size();
            while(l<r-1)
            {
                int m=(l+r)/2;
                vector<int> tmp;
                for(int i=l;i<m;i++) tmp.push_back(x[i]);
                if(q(tmp,y)==1) r=m;
                else l=m;
            }
            return x[l];
        };
        int x=go(one,two);
        vector<int> now;
        for(int y:two)
        {
            bool opt=1;
            for(int i=0;i<b;i++) opt&=(((id[x]>>i)&1)==((id[y]>>i)&1));
            if(opt) now.push_back(y);
        }
        int y=go(now,{x});
        setRoad(x,y);
        vector<vector<int>> nxt;
        for(int i=0;i<cc;i++) if(i!=id[x]&&i!=id[y]) nxt.push_back(v[i]);
        vector<int> tmp=v[id[x]];
        tmp.insert(tmp.end(),v[id[y]].begin(),v[id[y]].end());
        nxt.push_back(tmp);
        v=nxt;
    }
}

//int main()
//{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    run(5);
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 460 KB Ok! 94 queries used.
2 Correct 7 ms 460 KB Ok! 97 queries used.
# Verdict Execution time Memory Grader output
1 Correct 39 ms 508 KB Ok! 512 queries used.
2 Correct 40 ms 580 KB Ok! 519 queries used.
3 Correct 42 ms 460 KB Ok! 553 queries used.
# Verdict Execution time Memory Grader output
1 Correct 138 ms 612 KB Ok! 1380 queries used.
2 Correct 135 ms 512 KB Ok! 1367 queries used.
3 Correct 144 ms 496 KB Ok! 1477 queries used.
4 Correct 142 ms 460 KB Ok! 1430 queries used.
# Verdict Execution time Memory Grader output
1 Correct 140 ms 512 KB Ok! 1396 queries used.
2 Correct 141 ms 460 KB Ok! 1395 queries used.
3 Correct 134 ms 428 KB Ok! 1367 queries used.
4 Correct 141 ms 512 KB Ok! 1422 queries used.
# Verdict Execution time Memory Grader output
1 Correct 136 ms 460 KB Ok! 1367 queries used.
2 Correct 134 ms 508 KB Ok! 1372 queries used.
3 Correct 135 ms 512 KB Ok! 1376 queries used.
4 Correct 137 ms 516 KB Ok! 1401 queries used.
5 Correct 139 ms 508 KB Ok! 1398 queries used.
6 Correct 137 ms 516 KB Ok! 1389 queries used.
# Verdict Execution time Memory Grader output
1 Correct 133 ms 512 KB Ok! 1372 queries used.
2 Correct 137 ms 524 KB Ok! 1367 queries used.