Submission #914433

# Submission time Handle Problem Language Result Execution time Memory
914433 2024-01-22T05:57:22 Z Ghulam_Junaid Last supper (IOI12_supper) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "advisor.h"
#include "assistant.h"

using namespace std;

void ComputeAdvice(int *C, int N, int K, int M){
    int lg = 0;
    for (int i=0; i<20; i++){
        if ((1 << i) > N){
            lg = i;
            break;
        }
    }


    vector<int> g[N];
    int use[N] = {0};
    for (int i=0; i<N; i++)
        g[i].push_back(N + 1);
    for (int i=N-1; i>=0; i--)
        g[C[i]].push_back(i);

    for (int i=0; i<N; i++)
        use[i] = g[i].back();

    set<pair<int, int>> st;
    for (int i=0; i<K; i++)
        st.insert({use[i], i});

    for (int i=0; i<N; i++){
        if (st.find({use[C[i]], C[i]}) != st.end()){
            st.erase({use[C[i]], C[i]});
            g[C[i]].pop_back();
            use[C[i]] = g[C[i]].back();
            st.insert({use[C[i]], C[i]});
            continue;
        }

        auto p = *st.rbegin();
        
        int c = p.second;
        g[c].pop_back();

        if (g[c].size())
            use[c] = g[c].back();

        for (int j=0; j<lg; j++){
            if ((1 << j) & c){
                WriteAdvice(1);
            }
            else{
                WriteAdvice(0);
            }
        }

        // cout << "erasing " << c << " and getting " << C[i] << endl;

        st.erase(p);

        g[C[i]].pop_back();
        use[C[i]] = g[C[i]].back();

        st.insert({use[C[i]], C[i]});
    }
}

void Assist(unsigned char *A, int N, int K, int R){
    int lg = 0;
    for (int i=0; i<20; i++){
        if ((1 << i) > N){
            lg = i;
            break;
        }
    }

    set<int> st;
    for (int i=0; i<K; i++)
        st.insert(i);

    // cout << endl;

    int ind = 0;
    for (int i=0; i<N; i++){
        int x = GetRequest();
        if (st.find(x) != st.end())
            continue;

        int c = 0;
        for (int j=0; j<lg; j++)
            if ((int)A[ind + j])
                c += (1 << j);

        PutBack(c);
        st.erase(c);
        st.insert(x);

        // cout << "putting back " << c << endl;

        ind += lg;
    }
}
#include <bits/stdc++.h>
#include "advisor.h"
#include "assistant.h"

using namespace std;

void ComputeAdvice(int *C, int N, int K, int M){
    int lg = 0;
    for (int i=0; i<20; i++){
        if ((1 << i) > N){
            lg = i;
            break;
        }
    }


    vector<int> g[N];
    int use[N] = {0};
    for (int i=0; i<N; i++)
        g[i].push_back(N + 1);
    for (int i=N-1; i>=0; i--)
        g[C[i]].push_back(i);

    for (int i=0; i<N; i++)
        use[i] = g[i].back();

    set<pair<int, int>> st;
    for (int i=0; i<K; i++)
        st.insert({use[i], i});

    for (int i=0; i<N; i++){
        if (st.find({use[C[i]], C[i]}) != st.end()){
            st.erase({use[C[i]], C[i]});
            g[C[i]].pop_back();
            use[C[i]] = g[C[i]].back();
            st.insert({use[C[i]], C[i]});
            continue;
        }

        auto p = *st.rbegin();
        
        int c = p.second;
        g[c].pop_back();

        if (g[c].size())
            use[c] = g[c].back();

        for (int j=0; j<lg; j++){
            if ((1 << j) & c){
                WriteAdvice(1);
            }
            else{
                WriteAdvice(0);
            }
        }

        // cout << "erasing " << c << " and getting " << C[i] << endl;

        st.erase(p);

        g[C[i]].pop_back();
        use[C[i]] = g[C[i]].back();

        st.insert({use[C[i]], C[i]});
    }
}

void Assist(unsigned char *A, int N, int K, int R){
    int lg = 0;
    for (int i=0; i<20; i++){
        if ((1 << i) > N){
            lg = i;
            break;
        }
    }

    set<int> st;
    for (int i=0; i<K; i++)
        st.insert(i);

    // cout << endl;

    int ind = 0;
    for (int i=0; i<N; i++){
        int x = GetRequest();
        if (st.find(x) != st.end())
            continue;

        int c = 0;
        for (int j=0; j<lg; j++)
            if ((int)A[ind + j])
                c += (1 << j);

        PutBack(c);
        st.erase(c);
        st.insert(x);

        // cout << "putting back " << c << endl;

        ind += lg;
    }
}

Compilation message

/usr/bin/ld: /tmp/ccaDtx4n.o: in function `Assist(unsigned char*, int, int, int)':
advisor.cpp:(.text+0x511): undefined reference to `GetRequest()'
/usr/bin/ld: advisor.cpp:(.text+0x59b): undefined reference to `PutBack(int)'
collect2: error: ld returned 1 exit status

/usr/bin/ld: /tmp/ccIHxrz6.o: in function `ComputeAdvice(int*, int, int, int)':
assistant.cpp:(.text+0xc36): undefined reference to `WriteAdvice(unsigned char)'
/usr/bin/ld: assistant.cpp:(.text+0xc50): undefined reference to `WriteAdvice(unsigned char)'
collect2: error: ld returned 1 exit status