#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);
std::vector<int> where(N,-1);//index in cache for this color, or -1 if not present
for(int i=0;i<K;i++){
cache[i]=i;
where[i]=i;
}
for(int i=0;i<N;i++){
int late=0;
for(int k=0;k<K;k++){
if(next[cache[k]]>next[cache[late]]){
late=k;
}
}
if(where[C[i]]!=-1){
late=where[C[i]];
reuse[cache[late]]=true;
}
//evict cache[late]
where[colors[cache[late]]]=-1;
cache[late]=i+K;
where[colors[cache[late]]]=late;
}
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 time |
Memory |
Grader output |
1 |
Correct |
4 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
624 KB |
Output is correct |
3 |
Correct |
11 ms |
760 KB |
Output is correct |
4 |
Correct |
7 ms |
900 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
9 ms |
1040 KB |
Output is correct |
7 |
Correct |
23 ms |
1256 KB |
Output is correct |
8 |
Correct |
38 ms |
976 KB |
Output is correct |
9 |
Correct |
31 ms |
976 KB |
Output is correct |
10 |
Correct |
69 ms |
1048 KB |
Output is correct |
11 |
Correct |
46 ms |
1120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
1520 KB |
Output is correct |
2 |
Correct |
1305 ms |
3248 KB |
Output is correct |
3 |
Execution timed out |
2533 ms |
3184 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2518 ms |
2620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1048 KB |
Output is correct |
2 |
Correct |
45 ms |
968 KB |
Output is correct |
3 |
Correct |
7 ms |
1036 KB |
Output is correct |
4 |
Correct |
7 ms |
984 KB |
Output is correct |
5 |
Correct |
8 ms |
1240 KB |
Output is correct |
6 |
Correct |
10 ms |
984 KB |
Output is correct |
7 |
Correct |
28 ms |
1028 KB |
Output is correct |
8 |
Correct |
40 ms |
1028 KB |
Output is correct |
9 |
Correct |
47 ms |
1052 KB |
Output is correct |
10 |
Correct |
128 ms |
1204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2513 ms |
3028 KB |
Time limit exceeded |
2 |
Execution timed out |
2549 ms |
3056 KB |
Time limit exceeded |
3 |
Execution timed out |
2537 ms |
3056 KB |
Time limit exceeded |
4 |
Execution timed out |
2527 ms |
3184 KB |
Time limit exceeded |
5 |
Execution timed out |
2559 ms |
3060 KB |
Time limit exceeded |
6 |
Execution timed out |
2569 ms |
3056 KB |
Time limit exceeded |
7 |
Execution timed out |
2568 ms |
3056 KB |
Time limit exceeded |
8 |
Execution timed out |
2555 ms |
3056 KB |
Time limit exceeded |
9 |
Execution timed out |
2535 ms |
3056 KB |
Time limit exceeded |
10 |
Execution timed out |
2565 ms |
3056 KB |
Time limit exceeded |