#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M) {
map<int,int> aparicoes;
for(int vez = 0;vez<N;vez++){
int numero = C[vez];
if(!aparicoes.count(numero)){
WriteAdvice(0);
aparicoes[numero] = vez;
for(int i = 0;(1 << i) <= N;i++){
if(numero & (1 << i)) WriteAdvice(1);
else WriteAdvice(0);
}
}
else{
int qual = aparicoes[numero];
WriteAdvice(1);
for(int i = 0;(1 << i) <= vez + 1;i++){
if(qual & (1 << i)) WriteAdvice(1);
else WriteAdvice(0);
}
}
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef pair<int,int> ii;
void Assist(unsigned char *A, int N, int K, int R) {
int ptr = 0;
map<int,int> last,atual;
vector<int> sequencia,vaiprecisar;
set<ii> sca;
set<int> defato;
for(int i = 0;i<=N;i++) last[i] = N + 1;
for(int i = 0;i<N;i++){
int flag = A[ptr];
ptr++;
if(!flag){
int numero = 0;
for(int j = 0;(1 << j) <= N;j++){
if(A[ptr] == 1) numero += (1 << j);
ptr++;
}
sequencia.push_back(numero);
}
else{
int numero = 0;
for(int j = 0;(1 << j) <= i + 1;j++){
if(A[ptr]) numero += (1 << j);
ptr++;
}
sequencia.push_back(sequencia[numero]);
}
}
for(int i = N-1;i>=0;i--){
int v = sequencia[i];
vaiprecisar.push_back(last[v]);
last[v] = i;
}
reverse(vaiprecisar.begin(),vaiprecisar.end());
//for(int i = 0;i<N;i++){
// printf("Foi %d %d\n",sequencia[i],vaiprecisar[i]);
//}
for(int i = 0;i<K;i++){
ii davez = ii(-last[i],i);
sca.insert(davez);
atual[i] = last[i];
defato.insert(i);
}
for(int i = 0;i<N;i++){
int v = sequencia[i];
int checagem = GetRequest();
if(defato.count(v)){
ii antigo = ii(-last[v],v);
last[v] = vaiprecisar[i];
ii novo = ii(-vaiprecisar[i],v);
sca.erase(antigo);
sca.insert(novo);
}
else{
ii perdeu = *(sca.begin());
sca.erase(perdeu);
defato.erase(perdeu.second);
PutBack(perdeu.second);
last[v] = vaiprecisar[i];
ii novo = ii(-vaiprecisar[i],v);
sca.insert(novo);
defato.insert(v);
}
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:58:7: warning: unused variable 'checagem' [-Wunused-variable]
int checagem = GetRequest();
^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
608 KB |
Output is correct |
2 |
Correct |
6 ms |
720 KB |
Output is correct |
3 |
Correct |
12 ms |
1032 KB |
Output is correct |
4 |
Correct |
15 ms |
1528 KB |
Output is correct |
5 |
Incorrect |
8 ms |
1752 KB |
Error - advice is too long |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
3444 KB |
Output is correct |
2 |
Correct |
395 ms |
11120 KB |
Output is correct |
3 |
Correct |
903 ms |
28224 KB |
Output is correct |
4 |
Correct |
802 ms |
34880 KB |
Output is correct |
5 |
Correct |
776 ms |
34880 KB |
Output is correct |
6 |
Correct |
811 ms |
34880 KB |
Output is correct |
7 |
Correct |
866 ms |
34880 KB |
Output is correct |
8 |
Correct |
884 ms |
34880 KB |
Output is correct |
9 |
Correct |
730 ms |
34880 KB |
Output is correct |
10 |
Correct |
1058 ms |
34880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
713 ms |
34880 KB |
Output is correct |
2 |
Incorrect |
91 ms |
34880 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
34880 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1168 ms |
34880 KB |
Output is partially correct - 1776047 bits used |
2 |
Partially correct |
945 ms |
34880 KB |
Output is partially correct - 1776165 bits used |
3 |
Partially correct |
966 ms |
34880 KB |
Output is partially correct - 1776153 bits used |
4 |
Partially correct |
1069 ms |
34880 KB |
Output is partially correct - 1776239 bits used |
5 |
Partially correct |
990 ms |
34880 KB |
Output is partially correct - 1776157 bits used |
6 |
Partially correct |
976 ms |
34880 KB |
Output is partially correct - 1775815 bits used |
7 |
Partially correct |
919 ms |
34880 KB |
Output is partially correct - 1772969 bits used |
8 |
Partially correct |
970 ms |
34880 KB |
Output is partially correct - 1776224 bits used |
9 |
Partially correct |
1074 ms |
34880 KB |
Output is partially correct - 1776116 bits used |
10 |
Partially correct |
1151 ms |
34880 KB |
Output is partially correct - 1800000 bits used |