#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
void ComputeAdvice(int *C, int N, int K, int M) {
int B = log2(K);
vector<int> idx[N];
for (int i = 0; i < N; i++) {
idx[C[i]].push_back(i);
}
for (int i = 0; i < N; i++) {
idx[i].push_back(N);
reverse(all(idx[i]));
}
int shelf[K];
set<pair<int, int>> st, pq;
for (int i = 0; i < K; i++) {
shelf[i] = i;
st.insert(make_pair(i, i)); // (color, posicion)
pq.insert(make_pair(-idx[i].back(), i)); // (proxima aparicion, posicion)
}
for (int i = 0; i < N; i++) {
int x = C[i];
auto it = st.lower_bound(make_pair(x, 0));
if (it != st.end() && it->first == x) {
pq.erase(make_pair(-idx[x].back(), it->second));
while (idx[x].back() <= i) idx[x].pop_back();
pq.insert(make_pair(-idx[x].back(), it->second));
continue;
}
int y = pq.begin()->second;
pq.erase(pq.begin());
st.erase(make_pair(shelf[y], y));
for (int j = B; j >= 0; j--) {
if ((y >> j) & 1) WriteAdvice(1);
else WriteAdvice(0);
}
shelf[y] = x;
st.insert(make_pair(x, y));
while (idx[x].back() <= i) idx[x].pop_back();
pq.insert(make_pair(-idx[x].back(), y));
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
int B = log2(K);
int shelf[K];
set<int> st;
for (int i = 0; i < K; i++) {
shelf[i] = i;
st.insert(i);
}
int curr = 0;
for (int i = 0; i < N; i++) {
int x = GetRequest();
if (st.find(x) != st.end()) continue;
int y = 0;
for (int j = B; j >= 0; j--) {
if (A[curr++] == 1) y ^= (1 << j);
}
PutBack(shelf[y]);
st.erase(shelf[y]);
shelf[y] = x;
st.insert(x);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
780 KB |
Output is correct |
2 |
Correct |
0 ms |
792 KB |
Output is correct |
3 |
Correct |
2 ms |
780 KB |
Output is correct |
4 |
Correct |
3 ms |
1076 KB |
Output is correct |
5 |
Correct |
4 ms |
1208 KB |
Output is correct |
6 |
Correct |
8 ms |
1400 KB |
Output is correct |
7 |
Correct |
4 ms |
1092 KB |
Output is correct |
8 |
Correct |
8 ms |
1684 KB |
Output is correct |
9 |
Correct |
10 ms |
1416 KB |
Output is correct |
10 |
Correct |
9 ms |
1392 KB |
Output is correct |
11 |
Correct |
8 ms |
1392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2268 KB |
Output is correct |
2 |
Correct |
84 ms |
7428 KB |
Output is correct |
3 |
Correct |
261 ms |
20092 KB |
Output is correct |
4 |
Correct |
145 ms |
12928 KB |
Output is correct |
5 |
Correct |
205 ms |
14948 KB |
Output is correct |
6 |
Correct |
234 ms |
15968 KB |
Output is correct |
7 |
Correct |
230 ms |
17116 KB |
Output is correct |
8 |
Correct |
237 ms |
17024 KB |
Output is correct |
9 |
Correct |
136 ms |
11960 KB |
Output is correct |
10 |
Correct |
224 ms |
17664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
176 ms |
12820 KB |
Output is correct |
2 |
Correct |
222 ms |
17144 KB |
Output is correct |
3 |
Correct |
244 ms |
17156 KB |
Output is correct |
4 |
Correct |
227 ms |
17076 KB |
Output is correct |
5 |
Correct |
177 ms |
15168 KB |
Output is correct |
6 |
Correct |
241 ms |
17084 KB |
Output is correct |
7 |
Correct |
231 ms |
17112 KB |
Output is correct |
8 |
Correct |
257 ms |
19908 KB |
Output is correct |
9 |
Correct |
170 ms |
15676 KB |
Output is correct |
10 |
Correct |
228 ms |
17768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1052 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
15932 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
230 ms |
15924 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
225 ms |
16448 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
235 ms |
16264 KB |
Output is partially correct - 712005 bits used |
5 |
Correct |
236 ms |
16108 KB |
Output is partially correct - 710610 bits used |
6 |
Correct |
223 ms |
16352 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
239 ms |
16148 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
222 ms |
16052 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
240 ms |
16016 KB |
Output is partially correct - 712830 bits used |
10 |
Correct |
257 ms |
18552 KB |
Output is partially correct - 1117620 bits used |