#include "advisor.h"
#include <vector>
#include <set>
#include <cmath>
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M) {
int logn=log(N)+1;
for(int i=0;i<N;i++){
int x=C[i];
for(int j=0;j<logn;j++){
if(x&1)WriteAdvice(1);
else WriteAdvice(0);
x/=2;
}
}
}
#include "assistant.h"
#include <vector>
#include <set>
#include <cmath>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
int logn=log(N)+1;
vector<int> V(N),cnt(N);
set<int> S;
set<pair<int,int>> M;
for(int i=0;i<K;i++)S.insert(i);
for(int i=0;i<N;i++){
for(int j=19;j>=0;j--){
V[i]*=2;
V[i]+=(int)(A[i*20+j]);
}
}
vector<vector<int>> needed(N,vector<int>());
for(int i=0;i<N;i++){
needed[V[i]].push_back(i);
}
for(int i=0;i<N;i++)needed[i].push_back(N);
for(int i=0;i<K;i++){
M.insert({-needed[i][0],i});
}
for (int i = 0; i < N; i++) {
int req = GetRequest();
if (S.find(req)==S.end()){
auto it=M.begin();
S.erase(it->second);
S.insert(req);
PutBack(it->second);
M.erase(it);
cnt[req]++;
M.insert({-needed[req][cnt[req]],req});
}
else{
M.erase({-needed[req][cnt[req]],req});
cnt[req]++;
M.insert({-needed[req][cnt[req]],req});
}
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:7:11: warning: unused variable 'logn' [-Wunused-variable]
7 | int logn=log(N)+1;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
2408 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
206 ms |
12444 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
508 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
257 ms |
14908 KB |
Execution killed with signal 11 |
2 |
Runtime error |
268 ms |
15156 KB |
Execution killed with signal 11 |
3 |
Runtime error |
251 ms |
15416 KB |
Execution killed with signal 11 |
4 |
Runtime error |
253 ms |
15348 KB |
Execution killed with signal 11 |
5 |
Runtime error |
253 ms |
15512 KB |
Execution killed with signal 11 |
6 |
Runtime error |
244 ms |
15412 KB |
Execution killed with signal 11 |
7 |
Runtime error |
266 ms |
15376 KB |
Execution killed with signal 11 |
8 |
Runtime error |
243 ms |
15484 KB |
Execution killed with signal 11 |
9 |
Runtime error |
249 ms |
15452 KB |
Execution killed with signal 11 |
10 |
Runtime error |
243 ms |
15376 KB |
Execution killed with signal 11 |