Submission #430112

# Submission time Handle Problem Language Result Execution time Memory
430112 2021-06-16T11:31:43 Z someone Last supper (IOI12_supper) C++14
Compilation error
0 ms 0 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;

struct Val {
    int i, val;

    bool operator <(const Val& v) const {
        return val > v.val;
    }
};

const int N = 1e5 + 10, INF = 1e9;

bool on[N];
char ch[] = {'0', '1'};
deque<int> pos[N], v[2];
int n1, m1, k1, c[N], nbbits1;

void addId(int i, int val, int bits) {
    if(bits == 0)
        return;
    addId(i, val/2, bits-1);
    v[i].push_back(val % 2);
    //cout << val % 2;
}

void compute(int id) {
    set<Val> last;
    vector<int> suppr;
    for(int i = 0; i < n1; i++) {
        on[i] = false;
        pos[i].clear();
    }
    for(int i = 0; i < n1; i++)
        pos[c[i]].push_back(i);
    for(int i = 0; i < k1; i++) {
        if(id == 1) {
            if(pos[i].size() == 0)
                v[id].push_back(1);
            else
                v[id].push_back(0);
        }
        on[i] = true;
        last.insert({i, pos[i][0]});
    }
    for(int i = 0; i < n1; i++)
        pos[i].push_back(INF);

    for(int i = 0; i < n1; i++) {
        if(!on[c[i]]) {
            on[c[i]] = true;
            auto it = last.end();
            it--;
            if(id == 1) {
                if(pos[c[i]][0] == INF) {
                    v[id].push_back(1);
                    //cout << 1 << ' ';
                } else {
                    v[id].push_back(0);
                    //cout << 0 << ' ';
                }
                if(suppr.empty()) {
                    addId(id, (*it).i, nbbits1);
                    //cout << ' ' ;
                    last.erase(it);
                }
            } else {
                addId(id, (*it).i, nbbits1);
                //cout << ' ' ;
                last.erase(it);
            }
            last.insert({c[i], pos[c[i]][0]});
            pos[c[i]].pop_front();
        }
    }
}

void ComputeAdvice(int *C, int n2, int k2, int m2) {
    n1 = n2;
    k1 = k2;
    m1 = m2;
    v[0].push_back(0);
    v[1].push_back(1);

    nbbits1 = (int)ceil(log2(n1));
    //cout << "BITS " << nbbits1 << '\n';
    for(int i = 0; i < n1; i++)
        c[i] = C[i];
    compute(0);
    //cout << '\n';
    compute(1);
    if(v[0].size() < v[1].size()) {
        //cout << "0\n\n";
        for(int i : v[0]) {
            WriteAdvice(i);
        }
    } else {
        //cout << "1\n\n";
        for(int i : v[1]) {
            WriteAdvice(i);
        }
    }
}



    

Compilation message

/usr/bin/ld: /tmp/ccN7uf3s.o: in function `main':
assistant_grader.cpp:(.text.startup+0x21e): undefined reference to `Assist(unsigned char*, int, int, int)'
collect2: error: ld returned 1 exit status