#include "advisor.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
int E[100009], F[100009]; vector<int>X[100009];
priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>>Q;
void ComputeAdvice(int *C, int N, int K, int M) {
int BITS = 0; for (int i = 0; i < 19; i++) { if ((1 << i) >= K) { BITS = i; break; } }
for (int i = 0; i < N; i++) X[C[i]].push_back(i);
for (int i = 0; i < N; i++) X[i].push_back(N);
for (int i = 0; i < N; i++) E[i] = -1;
for (int i = 0; i < K; i++) E[i] = i;
for (int i = 0; i < N; i++) { Q.push(make_pair(X[i][0], i)); }
for (int i = 0; i < N; i++) {
while (true) {
int pos1 = Q.top().first, pos2 = Q.top().second;
if (E[pos2] == -1) Q.pop();
else break;
}
if (E[C[i]] != -1) F[i] = -1;
else {
int pos1 = Q.top().second;
F[i] = E[pos1];
E[pos1] = -1;
E[C[i]] = F[i];
}
int pos1 = lower_bound(X[C[i]].begin(), X[C[i]].end(), i + 1) - X[C[i]].begin();
Q.push(make_pair(X[C[i]][pos1], C[i]));
}
for (int i = 0; i < N; i++) {
if (F[i] == -1) continue;
for (int j = 0; j < BITS; j++) {
WriteAdvice((F[i] / (1 << j)) % 2);
}
}
}
#include "assistant.h"
#include <iostream>
using namespace std;
bool used[100009]; int LIST[100009];
void Assist(unsigned char *A, int N, int K, int R) {
int BITS = 0; for (int i = 0; i < 19; i++) { if ((1 << i) >= K) { BITS = i; break; } }
for (int i = 0; i < K; i++) { used[i] = true; LIST[i] = i; }
int cnts = 0;
for (int i = 0; i < N; i++) {
int V = GetRequest();
if (used[V] == true) continue;
else {
int sum = 0;
for (int j = 0; j < BITS; j++) {
sum += A[cnts] * (1 << j); cnts++;
}
PutBack(LIST[sum]);
used[V] = true; used[LIST[sum]] = false;
LIST[sum] = V;
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:23:8: warning: unused variable 'pos1' [-Wunused-variable]
int pos1 = Q.top().first, pos2 = Q.top().second;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5376 KB |
Output is correct |
2 |
Correct |
6 ms |
5376 KB |
Output is correct |
3 |
Correct |
7 ms |
5376 KB |
Output is correct |
4 |
Correct |
7 ms |
5888 KB |
Output is correct |
5 |
Correct |
9 ms |
5976 KB |
Output is correct |
6 |
Correct |
13 ms |
6400 KB |
Output is correct |
7 |
Correct |
10 ms |
6144 KB |
Output is correct |
8 |
Correct |
13 ms |
6400 KB |
Output is correct |
9 |
Correct |
15 ms |
6400 KB |
Output is correct |
10 |
Correct |
12 ms |
6400 KB |
Output is correct |
11 |
Correct |
12 ms |
6144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
7168 KB |
Output is correct |
2 |
Correct |
88 ms |
13800 KB |
Output is correct |
3 |
Correct |
232 ms |
24368 KB |
Output is correct |
4 |
Correct |
199 ms |
21528 KB |
Output is correct |
5 |
Correct |
238 ms |
23512 KB |
Output is correct |
6 |
Correct |
245 ms |
23672 KB |
Output is correct |
7 |
Correct |
224 ms |
23208 KB |
Output is correct |
8 |
Correct |
228 ms |
22048 KB |
Output is correct |
9 |
Correct |
148 ms |
21016 KB |
Output is correct |
10 |
Correct |
214 ms |
22832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
19464 KB |
Output is correct |
2 |
Correct |
208 ms |
22696 KB |
Output is correct |
3 |
Correct |
214 ms |
22776 KB |
Output is correct |
4 |
Correct |
207 ms |
22232 KB |
Output is correct |
5 |
Correct |
153 ms |
21216 KB |
Output is correct |
6 |
Correct |
201 ms |
22784 KB |
Output is correct |
7 |
Correct |
198 ms |
22840 KB |
Output is correct |
8 |
Correct |
267 ms |
25152 KB |
Output is correct |
9 |
Correct |
143 ms |
21400 KB |
Output is correct |
10 |
Correct |
214 ms |
22624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
6080 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
224 ms |
23032 KB |
Output is partially correct - 772365 bits used |
2 |
Partially correct |
213 ms |
22880 KB |
Output is partially correct - 742095 bits used |
3 |
Partially correct |
215 ms |
22760 KB |
Output is partially correct - 712470 bits used |
4 |
Partially correct |
226 ms |
22688 KB |
Output is partially correct - 712005 bits used |
5 |
Partially correct |
218 ms |
22696 KB |
Output is partially correct - 710610 bits used |
6 |
Partially correct |
204 ms |
22824 KB |
Output is partially correct - 712155 bits used |
7 |
Partially correct |
224 ms |
22576 KB |
Output is partially correct - 711090 bits used |
8 |
Partially correct |
228 ms |
22936 KB |
Output is partially correct - 713340 bits used |
9 |
Partially correct |
212 ms |
22752 KB |
Output is partially correct - 712830 bits used |
10 |
Partially correct |
292 ms |
24976 KB |
Output is partially correct - 1117620 bits used |