답안 #130693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130693 2019-07-15T22:20:34 Z dragonslayerit 최후의 만찬 (IOI12_supper) C++14
43 / 100
2500 ms 3696 KB
#include "advisor.h"
#include <vector>


void ComputeAdvice(int *C, int N, int K, int M) {
  std::vector<int> reuse(K+N,false);
  std::vector<int> next(N);
  std::vector<int> first(N,N);
  for(int i=N-1;i>=0;i--){
    next[i]=first[C[i]];
    first[C[i]]=i;
  }
  next.insert(next.begin(),first.begin(),first.begin()+K);
  std::vector<int> colors;
  for(int i=0;i<K;i++){
    colors.push_back(i);
  }
  colors.insert(colors.end(),C,C+N);
  //time entered: [0,K) for init, [K,N+K) for added
  //time color will be reused: next[cache[i]]
  std::vector<int> cache(K);
  for(int i=0;i<K;i++){
    cache[i]=i;
  }
  for(int i=0;i<N;i++){
    int late=0;
    for(int k=0;k<K;k++){
      if(colors[cache[k]]==C[i]){
	late=k;
	break;
      }
      if(next[cache[k]]>next[cache[late]]){
	late=k;
      }
    }
    if(colors[cache[late]]==C[i]){
      reuse[cache[late]]=true;
    }
    //evict cache[late]
    cache[late]=i+K;
  }
  for(int i=0;i<K+N;i++){
    WriteAdvice(reuse[i]);
  }
}
#include "assistant.h"
#include <vector>

void Assist(unsigned char *A, int N, int K, int R) {
  std::vector<int> advice(A,A+R);
  std::vector<std::pair<int,int> > cache(K);//(color,reused)
  for(int i=0;i<K;i++){
    cache[i]={i,advice[i]};
  }
  for(int i=0;i<N;i++){
    int color=GetRequest();
    int evict=0;
    for(int k=0;k<K;k++){
      if(cache[k].first==color){
	evict=k;
	break;
      }
      if(!cache[k].second){
	evict=k;
      }
    }
    if(cache[evict].first!=color){
      PutBack(cache[evict].first);
    }
    cache[evict].first=color;
    cache[evict].second=advice[i+K];
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 776 KB Output is correct
2 Correct 4 ms 1008 KB Output is correct
3 Correct 7 ms 780 KB Output is correct
4 Correct 6 ms 928 KB Output is correct
5 Correct 7 ms 1040 KB Output is correct
6 Correct 10 ms 1172 KB Output is correct
7 Correct 15 ms 1128 KB Output is correct
8 Correct 37 ms 1076 KB Output is correct
9 Correct 30 ms 1264 KB Output is correct
10 Correct 49 ms 1072 KB Output is correct
11 Correct 35 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 1416 KB Output is correct
2 Correct 965 ms 3624 KB Output is correct
3 Execution timed out 2560 ms 3696 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2524 ms 3004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1008 KB Output is correct
2 Correct 42 ms 1096 KB Output is correct
3 Correct 7 ms 1068 KB Output is correct
4 Correct 7 ms 1068 KB Output is correct
5 Correct 9 ms 1128 KB Output is correct
6 Correct 11 ms 1076 KB Output is correct
7 Correct 25 ms 1136 KB Output is correct
8 Correct 32 ms 1132 KB Output is correct
9 Correct 35 ms 1008 KB Output is correct
10 Correct 77 ms 1296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2555 ms 3440 KB Time limit exceeded
2 Execution timed out 2545 ms 3312 KB Time limit exceeded
3 Execution timed out 2547 ms 3312 KB Time limit exceeded
4 Execution timed out 2554 ms 3316 KB Time limit exceeded
5 Execution timed out 2561 ms 3440 KB Time limit exceeded
6 Execution timed out 2548 ms 3440 KB Time limit exceeded
7 Execution timed out 2547 ms 3312 KB Time limit exceeded
8 Execution timed out 2563 ms 3440 KB Time limit exceeded
9 Execution timed out 2567 ms 3444 KB Time limit exceeded
10 Execution timed out 2571 ms 3440 KB Time limit exceeded