Submission #958990

# Submission time Handle Problem Language Result Execution time Memory
958990 2024-04-07T10:55:41 Z vjudge1 Last supper (IOI12_supper) C++17
Compilation error
0 ms 0 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

void ComputeAdvice(int *C, int N, int K, int M) {
  int B = log2(K);

  vector<int> idx[N];
  for (int i = 0; i < N; i++) {
    idx[C[i]].push_back(i);
  }
  for (int i = 0; i < N; i++) {
    idx[i].push_back(N);
    reverse(all(idx[i]));
  }

  int shelf[K];
  set<pair<int, int>> st, pq;
  for (int i = 0; i < K; i++) {
    shelf[i] = i;
    st.insert(make_pair(i, i)); // (color, posicion)
    pq.insert(make_pair(-idx[i].back(), i)); // (proxima aparicion, posicion)
  }

  for (int i = 0; i < N; i++) {
    int x = C[i];

    auto it = st.lower_bound(make_pair(x, 0));
    if (it != st.end() && it->first == x) {
      pq.erase(make_pair(-idx[x].back(), it->second));

      while (idx[x].back() <= i) idx[x].pop_back();
      pq.insert(make_pair(-idx[x].back(), it->second));
      
      continue;
    }

    int y = pq.begin()->second;
    pq.erase(pq.begin());

    st.erase(make_pair(shelf[y], y));

    for (int j = B; j >= 0; j--) {
      if ((y >> j) & 1) WriteAdvice(1);
      else WriteAdvice(0);
    }
    
    shelf[y] = x;
    st.insert(make_pair(x, y));

    while (idx[x].back() <= i) idx[x].pop_back();
    pq.insert(make_pair(-idx[x].back(), y));
  }
}



    

Compilation message

/usr/bin/ld: /tmp/ccmsbWhk.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