답안 #58846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58846 2018-07-19T16:04:51 Z gabrielsimoes 최후의 만찬 (IOI12_supper) C++17
43 / 100
444 ms 30976 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 int bitNum = 1;
static int current[MAXN];
static set<pii> nxRemove;

void putNum(int x) {
  // printf("putNum %d\n", x);
  for (int i = 0; i < bitNum; i++)
    WriteAdvice(!!((x >> i) & 1));
}

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) {
  while ((1 << bitNum) < K) bitNum++;

  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;

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

  for (int i = 0; i < N; i++) {
    // printf("request %d\n", C[i]);
    // for (int k = 0; k < N; k++)
    //   printf("current[%d] %d\n", k, current[k]);
    // printf("nxRemove: ");
    // for (pii p : nxRemove) printf(" (%d,%d)", p.first, p.second);
    // printf("\n");


    if (current[C[i]] != -1) {
      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]});

      putNum(current[toRemove]);

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

const int MAXN = 100000;
static int palette[MAXN];
static bool current[MAXN];
static int bitNum = 1;

int getNum(unsigned char *A) {
  static int i = 0;

  int ret = 0;
  for (int k = 0; k < bitNum; k++) {
    if (A[i++]) ret ^= (1 << k);
  }

  // printf("getNum %d\n", ret);

  return ret;
}

void Assist(unsigned char *A, int N, int K, int R) {
  while ((1 << bitNum) < K) bitNum++;

  for (int i = 0; i < K; i++) palette[i] = i, current[i] = true;

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

    if (current[req]) {
      continue;
    }

    int pos = getNum(A);

    PutBack(palette[pos]);

    current[palette[pos]] = false;
    current[req] = true;
    palette[pos] = req;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5360 KB Output is correct
2 Correct 8 ms 5472 KB Output is correct
3 Correct 8 ms 5640 KB Output is correct
4 Correct 11 ms 5656 KB Output is correct
5 Correct 14 ms 5952 KB Output is correct
6 Correct 19 ms 6272 KB Output is correct
7 Correct 13 ms 6272 KB Output is correct
8 Correct 20 ms 6848 KB Output is correct
9 Correct 23 ms 6848 KB Output is correct
10 Correct 17 ms 6848 KB Output is correct
11 Correct 18 ms 6848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7328 KB Output is correct
2 Correct 115 ms 11416 KB Output is correct
3 Correct 379 ms 24672 KB Output is correct
4 Correct 211 ms 24672 KB Output is correct
5 Correct 353 ms 24672 KB Output is correct
6 Correct 325 ms 24672 KB Output is correct
7 Correct 313 ms 25728 KB Output is correct
8 Correct 299 ms 28312 KB Output is correct
9 Correct 181 ms 28312 KB Output is correct
10 Correct 421 ms 28312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 28312 KB Output is correct
2 Correct 315 ms 28312 KB Output is correct
3 Correct 325 ms 28312 KB Output is correct
4 Correct 417 ms 28312 KB Output is correct
5 Correct 282 ms 28312 KB Output is correct
6 Correct 339 ms 28312 KB Output is correct
7 Correct 303 ms 28312 KB Output is correct
8 Correct 366 ms 30976 KB Output is correct
9 Correct 271 ms 30976 KB Output is correct
10 Correct 309 ms 30976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 30976 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 301 ms 30976 KB Output is partially correct - 772365 bits used
2 Partially correct 295 ms 30976 KB Output is partially correct - 742095 bits used
3 Partially correct 286 ms 30976 KB Output is partially correct - 712470 bits used
4 Partially correct 305 ms 30976 KB Output is partially correct - 712005 bits used
5 Partially correct 318 ms 30976 KB Output is partially correct - 710610 bits used
6 Partially correct 288 ms 30976 KB Output is partially correct - 712155 bits used
7 Partially correct 363 ms 30976 KB Output is partially correct - 711090 bits used
8 Partially correct 365 ms 30976 KB Output is partially correct - 713340 bits used
9 Partially correct 361 ms 30976 KB Output is partially correct - 712830 bits used
10 Partially correct 444 ms 30976 KB Output is partially correct - 1117620 bits used