제출 #1237745

#제출 시각아이디문제언어결과실행 시간메모리
1237745guanexLast supper (IOI12_supper)C++20
41 / 100
190 ms70588 KiB

#include "advisor.h"

#include<bits/stdc++.h>

using namespace std;

void ComputeAdvice(int *C, int N, int K, int M) {
  vector<int> scaff;
  vector<queue<int>> app(N);
  for(int i = 0; i < N; ++i){
    app[C[i]].push(i);
  }
  int pos[N];
  memset(pos, -1, sizeof pos);
  priority_queue<pair<int, int>> q;
  for(int i = 0; i < K; ++i){
    scaff.push_back(i);
    pos[i] = i;
    if((int)app[i].size() == 0){
      q.push({1e6, i});
    }else{
      q.push({app[i].front(), i});
    }
  }
  vector<int> out;
  for(int i = 0; i < N; ++i){
    int req = C[i];
    if(pos[req] == -1){
      pair<int, int> far = q.top();
      q.pop();
      int npos = pos[far.second];
      out.push_back(npos);
      pos[far.second] = -1;
      pos[req] = npos;
      while((int)app[req].size() > 0 && app[req].front() <= i){
        app[req].pop();
      }
      if((int)app[req].size() == 0){
        q.push({1e6, req});
      }else{
        q.push({app[req].front(), req});
      }
    }else{
      while((int)app[req].size() > 0 && app[req].front() <= i){
        app[req].pop();
      }
      if((int)app[req].size() == 0){
        q.push({1e6, req});
      }else{
        q.push({app[req].front(), req});
      }
    }
  }
  int bits = 0;
  int pot = 1;
  for(int i = 0; i < 30; ++i){
    if(pot >= K){
      bits = i;
      break;
    }
    pot *= 2;
  }
  for(auto e:out){
    for(int i = 0; i <= bits; ++i){
      if(e & (1 << i)){
        WriteAdvice(1);
        //cout << 1 << " ";
      }else{
        WriteAdvice(0);
        //cout << 0 << " ";
      }
    }
  }
  //cout << endl;
}

#include "assistant.h"

#include<bits/stdc++.h>

using namespace std;

void Assist(unsigned char *A, int N, int K, int R) {
  int bits = 0;
  int pot = 1;
  for(int i = 0; i < 30; ++i){
    if(pot >= K){
      bits = i;
      break;
    }
    pot *= 2;
  }
  int i = 0;
  vector<int> out;
  for(i; i < R; i += bits+1){
    int num = 0;
    int po = 1;
    for(int j = i; j <= i + bits; ++j){
      if(A[j]){
        num += po;
      }
      po *= 2;
    }
    out.push_back(num);
  }
  //cout << "nice" << endl;
  vector<int> scaff;
  int pos[N];
  memset(pos, -1, sizeof pos);
  for(int i = 0; i < K; ++i){
    scaff.push_back(i);
    pos[i] = i;
  }
  int j = 0;
  for (i = 0; i < N; i++) {
    int req = GetRequest();
    if(pos[req] != -1){
      continue;
    }
    int outnum = scaff[out[j]];
    PutBack(outnum);
    scaff[out[j]] = req;
    pos[req] = out[j];
    pos[outnum] = -1;
    j++;
  }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...