#include "advisor.h"
#include <vector>
#include <queue>
using namespace std;
typedef long long llong;
static vector<bool> used(100000, false);
static int nxt[100000];
static int pos[100000];
struct col {
int color;
int next;
bool operator<(const col &x) const {
return next < x.next;
}
};
static priority_queue<col> pq;
static vector<int> work[100000];
static int top[100000];
void ComputeAdvice(int *c, int n, int k, int m) {
for (int i = 0; i < n; ++i) pos[i] = -1, nxt[i] = n;
for (int i = 0; i < n; ++i) {
if (pos[c[i]] == -1) {
pos[c[i]] = i;
if (c[i] < k)
pq.push({ c[i], i });
}
else {
nxt[pos[c[i]]] = i;
pos[c[i]] = i;
}
}
for (int i = 0; i < n; ++i) {
if (pos[i] == -1) {
if (i < k)
pq.push({ i, n });
}
else {
nxt[pos[i]] = n;
}
}
for (int i = 0; i < k; ++i) used[i] = true;
for (int i = 0; i < n; ++i) {
if (used[c[i]]) {
work[c[i]].push_back(0);
}
else {
col t = pq.top();
pq.pop();
used[t.color] = false;
used[c[i]] = true;
work[c[i]].push_back(1);
}
pq.push({ c[i], nxt[i] });
}
for (int i = 0; i < n + k; ++i) {
int j = i < k ? i : c[i - k];
if (top[j] == work[j].size()) WriteAdvice(1);
else WriteAdvice(work[j][top[j]++]);
}
}
#include "assistant.h"
#include <vector>
static std::vector<bool> used(100000, false);
static int exclude[200000];
static int top, bot;
void Assist(unsigned char *advice, int n, int k, int r) {
for (int i = 0; i < k; ++i) {
used[i] = true;
if (advice[i]) exclude[top++] = i;
}
advice += k;
for (int i = 0; i < n; ++i) {
int req = GetRequest();
if (!used[req]) {
PutBack(exclude[bot]);
used[req] = true;
used[exclude[bot++]] = false;
}
if (advice[i]) exclude[top++] = req;
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:61:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (top[j] == work[j].size()) WriteAdvice(1);
~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5360 KB |
Output is correct |
2 |
Incorrect |
6 ms |
5832 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
6848 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
14152 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
14152 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
16000 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
97 ms |
16256 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
100 ms |
16256 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
99 ms |
16296 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
100 ms |
16304 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
100 ms |
16304 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
132 ms |
16304 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
107 ms |
16328 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
108 ms |
16328 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
100 ms |
18136 KB |
Output isn't correct - not an optimal way |