제출 #130697

#제출 시각아이디문제언어결과실행 시간메모리
130697dragonslayeritLast supper (IOI12_supper)C++14
100 / 100
2446 ms10152 KiB
#include "advisor.h" #include <vector> #include <set> 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: [0,K) for init, [K,N+K) for added std::set<std::pair<int,int> > pq;//(next time, previous time) std::vector<int> in(N,-1);//time of last appearance of color if in cache, -1 otherwise for(int i=0;i<K;i++){ in[i]=i; pq.insert({next[i],i}); } for(int i=0;i<N;i++){ int evict=pq.rbegin()->second; if(in[C[i]]!=-1){ evict=in[C[i]]; reuse[in[C[i]]]=true; } //evict 'evict' pq.erase({next[evict],evict}); in[colors[evict]]=-1; in[colors[i+K]]=i+K; pq.insert({next[i+K],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) std::vector<int> where(N,-1);//where in cache a color is, or -1 if not present for(int i=0;i<K;i++){ cache[i]={i,advice[i]}; where[i]=i; } for(int i=0;i<N;i++){ int color=GetRequest(); int evict=0; for(int k=0;k<K;k++){ if(!cache[k].second){ evict=k; } } if(where[color]!=-1){ evict=where[color]; } where[cache[evict].first]=-1; if(cache[evict].first!=color){ PutBack(cache[evict].first); } cache[evict].first=color; cache[evict].second=advice[i+K]; where[cache[evict].first]=evict; } }
#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...