#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
int post[1 << 18], I[1 << 18]; vector<int> Z[1 << 18];
bool used[1 << 18];
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i = 0; i < N; i++) Z[C[i]].push_back(i);
for (int i = 0; i < N; i++) post[i] = (1 << 30);
for (int i = 0; i < K; i++) {
for (int j = (int)Z[i].size() - 2; j >= 0; j--) post[Z[i][j]] = Z[i][j + 1];
}
priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>> que;
for (int i = 0; i < K; i++) {
used[i] = true; I[i] = i;
if (Z[i].size() >= 1) que.push(make_pair(Z[i][0], i));
else que.push(make_pair((1 << 30), i));
}
vector<int> L;
for (int i = 0; i < N; i++) {
if (used[C[i]] == false) {
pair<int, int> G = que.top(); que.pop();
used[G.second] = false; I[C[i]] = I[G.second]; L.push_back(I[C[i]]);
}
que.push(make_pair(post[i], C[i])); used[C[i]] = true;
}
int sz = 0, size_ = 1;
while (size_ < K) { size_ *= 2; sz++; }
for (int i = 0; i < L.size(); i++) {
for (int j = 0; j < sz; j++) WriteAdvice((L[i] / (1 << j)) % 2);
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
int LL[1 << 18], DAI[1 << 18]; bool used2[1 << 18];
void Assist(unsigned char *A, int N, int K, int R) {
int sz = 0, size_ = 1;
while (size_ < K) { size_ *= 2; sz++; }
for (int i = 0; i < R / sz; i++) {
for (int j = 0; j < sz; j++) { LL[i] += A[i * sz + j] * (1 << j); }
}
for (int i = 0; i < K; i++) { used2[i] = true; DAI[i] = i; }
int cnt = 0;
for (int i = 0; i < N; i++) {
int G = GetRequest();
if (used2[G] == false) {
int nex = LL[cnt]; //cout << "request = " << G << ", nex = " << nex << ", initial value = " << DAI[nex] << ", num = " << LL[cnt] << endl;
PutBack(DAI[nex]); cnt++;
used2[G] = true; used2[DAI[nex]] = false; DAI[nex] = G;
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); i++) {
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
13056 KB |
Output is correct |
2 |
Incorrect |
11 ms |
13056 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
14592 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
353 ms |
24984 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
13312 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
338 ms |
27992 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
376 ms |
27872 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
305 ms |
27512 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
348 ms |
27712 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
390 ms |
27608 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
385 ms |
27800 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
325 ms |
28024 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
401 ms |
27512 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
404 ms |
27960 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
311 ms |
29760 KB |
Output isn't correct - not an optimal way |