#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
string to_binary(int x){
string str;
int l = 31 - __builtin_clz(x);
for(int i=l;i>=0;i--)
str += (bool(x&(1<<i)) + '0');
return str;
}
void ComputeAdvice(int *C, int N, int K, int M) {
int digits = (31 - __builtin_clz(N)) + 1;
for(int i=0;i<N;i++){
string s = to_binary(C[i]);
for(int i=0;i<digits-int(s.size());i++) WriteAdvice(0);
for(auto& e : s)
WriteAdvice(e-'0');
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
int to_int(string const& s){
int ans=0, ct=0;
for(int i=s.size()-1;i>=0;i--)
ans += ((s[i]-'0') * (1<<ct)), ++ct;
return ans;
}
void Assist(unsigned char *A, int N, int K, int R) {
int digits = (31 - __builtin_clz(N)) + 1;
set<int> colors;
multiset<int> C;
vector<int> C2;
for(int i=0;i<digits*N;i+=digits){
string s;
for(int j=0;j<digits;j++)
s += (A[j+i]+'0') ;
C.insert(to_int(s));
C2.push_back(to_int(s));
}
for(int i=0;i<K;i++)
colors.insert(i);
for(int i=0;i<N;i++){
int x = GetRequest();
auto it = C.find(x);
if(it != C.end()) C.erase(it);
if(colors.find(x) != colors.end()) continue;
bool good = false;
for(auto& e : colors){
if(C.find(e) == C.end()){
good = true;
PutBack(e);
colors.erase(e);
break;
}
}
if(!good){
int ini=i, fim=N+1, meio;
while(fim - ini > 1){
meio = (ini + fim) >> 1;
if(colors.find(C2[meio]) != colors.end())
ini = meio;
else
fim = meio;
}
colors.erase(C2[ini]);
PutBack(C2[ini]);
}
colors.insert(x);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
612 KB |
Output is correct |
2 |
Execution timed out |
2535 ms |
263168 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2569 ms |
263168 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
213 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
191 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Execution timed out |
2529 ms |
263168 KB |
Time limit exceeded |
3 |
Runtime error |
203 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
4 |
Runtime error |
204 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
5 |
Runtime error |
222 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
6 |
Runtime error |
228 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
7 |
Execution timed out |
2534 ms |
263168 KB |
Time limit exceeded |
8 |
Runtime error |
220 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
9 |
Runtime error |
213 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
10 |
Runtime error |
202 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |