Submission #958966

# Submission time Handle Problem Language Result Execution time Memory
958966 2024-04-07T10:13:37 Z d4xn Last supper (IOI12_supper) C++17
0 / 100
292 ms 18692 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(), x));

      while (idx[x].back() <= i) idx[x].pop_back();
      pq.insert(make_pair(-idx[x].back(), x));
      
      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));
  }
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;

void Assist(unsigned char *A, int N, int K, int R) {
  int B = log2(K);

  int shelf[K];
  set<int> st;

  for (int i = 0; i < K; i++) {
    shelf[i] = i;
    st.insert(i);
  }

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

    int y = 0;
    for (int j = B; j >= 0; j--) {
      if (A[curr++] == 1) y ^= (1 << j);
    }

    PutBack(shelf[y]);
    st.erase(shelf[y]);

    shelf[y] = x;
    st.insert(x);
  }

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 780 KB Output is correct
2 Correct 1 ms 780 KB Output is correct
3 Correct 2 ms 784 KB Output is correct
4 Runtime error 1 ms 860 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2004 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 14812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1056 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 17120 KB Execution killed with signal 11
2 Runtime error 46 ms 17484 KB Execution killed with signal 11
3 Runtime error 73 ms 18636 KB Execution killed with signal 11
4 Runtime error 57 ms 18508 KB Execution killed with signal 11
5 Runtime error 68 ms 18556 KB Execution killed with signal 11
6 Runtime error 63 ms 18692 KB Execution killed with signal 11
7 Runtime error 74 ms 18516 KB Execution killed with signal 11
8 Runtime error 56 ms 18636 KB Execution killed with signal 11
9 Runtime error 58 ms 18516 KB Execution killed with signal 11
10 Correct 292 ms 18512 KB Output is partially correct - 1117620 bits used