#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[t.color].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 |
5368 KB |
Output is correct |
2 |
Correct |
5 ms |
5832 KB |
Output is correct |
3 |
Correct |
7 ms |
5832 KB |
Output is correct |
4 |
Correct |
8 ms |
6304 KB |
Output is correct |
5 |
Correct |
9 ms |
6440 KB |
Output is correct |
6 |
Correct |
10 ms |
6560 KB |
Output is correct |
7 |
Correct |
9 ms |
6560 KB |
Output is correct |
8 |
Correct |
9 ms |
6560 KB |
Output is correct |
9 |
Correct |
9 ms |
6560 KB |
Output is correct |
10 |
Correct |
9 ms |
6584 KB |
Output is correct |
11 |
Correct |
9 ms |
6584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7104 KB |
Output is correct |
2 |
Correct |
48 ms |
10168 KB |
Output is correct |
3 |
Correct |
102 ms |
16808 KB |
Output is correct |
4 |
Correct |
88 ms |
16808 KB |
Output is correct |
5 |
Correct |
98 ms |
16808 KB |
Output is correct |
6 |
Correct |
103 ms |
16808 KB |
Output is correct |
7 |
Correct |
111 ms |
16808 KB |
Output is correct |
8 |
Correct |
84 ms |
16808 KB |
Output is correct |
9 |
Correct |
84 ms |
16808 KB |
Output is correct |
10 |
Correct |
99 ms |
16808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
16808 KB |
Output is correct |
2 |
Correct |
109 ms |
16808 KB |
Output is correct |
3 |
Correct |
100 ms |
16808 KB |
Output is correct |
4 |
Correct |
98 ms |
16808 KB |
Output is correct |
5 |
Correct |
97 ms |
16808 KB |
Output is correct |
6 |
Correct |
99 ms |
16808 KB |
Output is correct |
7 |
Correct |
98 ms |
16808 KB |
Output is correct |
8 |
Correct |
98 ms |
17104 KB |
Output is correct |
9 |
Correct |
95 ms |
17104 KB |
Output is correct |
10 |
Correct |
104 ms |
17104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
17104 KB |
Output is correct |
2 |
Correct |
9 ms |
17104 KB |
Output is correct |
3 |
Correct |
9 ms |
17104 KB |
Output is correct |
4 |
Correct |
11 ms |
17104 KB |
Output is correct |
5 |
Correct |
9 ms |
17104 KB |
Output is correct |
6 |
Correct |
9 ms |
17104 KB |
Output is correct |
7 |
Correct |
9 ms |
17104 KB |
Output is correct |
8 |
Correct |
9 ms |
17104 KB |
Output is correct |
9 |
Correct |
9 ms |
17104 KB |
Output is correct |
10 |
Correct |
10 ms |
17104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
17104 KB |
Output is correct - 120000 bits used |
2 |
Correct |
97 ms |
17104 KB |
Output is correct - 122000 bits used |
3 |
Correct |
109 ms |
17104 KB |
Output is correct - 125000 bits used |
4 |
Correct |
116 ms |
17104 KB |
Output is correct - 125000 bits used |
5 |
Correct |
103 ms |
17104 KB |
Output is correct - 125000 bits used |
6 |
Correct |
105 ms |
17104 KB |
Output is correct - 125000 bits used |
7 |
Correct |
101 ms |
17104 KB |
Output is correct - 124828 bits used |
8 |
Correct |
100 ms |
17104 KB |
Output is correct - 124910 bits used |
9 |
Correct |
98 ms |
17104 KB |
Output is correct - 125000 bits used |
10 |
Correct |
97 ms |
17104 KB |
Output is correct - 125000 bits used |