답안 #58858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58858 2018-07-19T16:33:29 Z gabrielsimoes 최후의 만찬 (IOI12_supper) C++17
0 / 100
361 ms 23552 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100000;

typedef pair<int,int> pii;

static vector<int> v[MAXN];
static bool current[MAXN];
static set<pii> nxRemove;

int getNextUsage(int i) {
  if (v[i].empty()) return 1000000000;
  else {
    int ret = v[i].back();
    return ret;
  }
}

void ComputeAdvice(int *C, int N, int K, int M) {
  for (int i = 0; i < N; i++)
    v[C[i]].push_back(i);

  for (int i = 0; i < N; i++)
    reverse(v[i].begin(), v[i].end());

  for (int i = 0; i < N; i++) current[i] = -1;

  vector<int> stk;

  for (int i = 0; i < K; i++) {
    stk.push_back(i);
    current[i] = true;
    nxRemove.insert({getNextUsage(i), i});
  }

  for (int i = 0; i < N; i++) {
    if (current[C[i]]) {
      nxRemove.erase({getNextUsage(C[i]), C[i]});
      v[C[i]].pop_back();
      nxRemove.insert({getNextUsage(C[i]), C[i]});
    } else {
      auto it = prev(nxRemove.end());
      int toRemove = it->second;
      nxRemove.erase(it);

      v[C[i]].pop_back();
      nxRemove.insert({getNextUsage(C[i]), C[i]});

      while (stk.back() != toRemove) {
        WriteAdvice(1);
        int back = stk.back();
        stk.pop_back();
        stk.insert(stk.begin(), back);
      }

      WriteAdvice(0);
      stk.pop_back();
      stk.push_back(C[i]);

      current[C[i]] = true;
      current[toRemove] = false;
    }
  }
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100000;

static bool current[MAXN];
vector<int> stk;

bool getBit(unsigned char *A) {
  static int i = 0;
  return A[i++];
}

void Assist(unsigned char *A, int N, int K, int R) {
  for (int i = 0; i < K; i++) {
    stk.push_back(i);
    current[i] = true;
  }

  for (int i = 0; i < N; i++) {
    int req = GetRequest();

    if (current[req]) {
      continue;
    }

    while (getBit(A)) {
      int back = stk.back();
      stk.pop_back();
      stk.insert(stk.begin(), back);
    }

    PutBack(stk.back());
    current[stk.back()] = false;
    stk.pop_back();

    stk.push_back(req);
    current[req] = true;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5360 KB Output is correct
2 Incorrect 8 ms 5592 KB Output isn't correct - not an optimal way
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 7008 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 184 ms 16160 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 16160 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 293 ms 18688 KB Output isn't correct - not an optimal way
2 Incorrect 300 ms 19344 KB Output isn't correct - not an optimal way
3 Incorrect 349 ms 19344 KB Output isn't correct - not an optimal way
4 Incorrect 317 ms 19344 KB Output isn't correct - not an optimal way
5 Incorrect 361 ms 19344 KB Output isn't correct - not an optimal way
6 Incorrect 332 ms 19416 KB Output isn't correct - not an optimal way
7 Incorrect 287 ms 19416 KB Output isn't correct - not an optimal way
8 Incorrect 270 ms 19416 KB Output isn't correct - not an optimal way
9 Incorrect 267 ms 19416 KB Output isn't correct - not an optimal way
10 Incorrect 332 ms 23552 KB Output isn't correct - not an optimal way