#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
void ComputeAdvice(int *c, int n, int k, int m) {
vector<int> has(n);
for (int i = 0; i < k; i++) {
has[i] = true;
}
vector<set<int>> pos(n);
for (int i = 0; i < n; i++) {
pos[c[i]].insert(i);
}
set<pair<int, int>> st;
for (int i = 0; i < k; i++) {
if (pos[i].empty()) {
st.emplace(n, i);
} else {
st.emplace(*pos[i].begin(), i);
}
}
vector<bool> use(n);
for (int i = 0; i < n; i++) {
pos[c[i]].erase(pos[c[i]].find(i));
if (has[c[i]]) {
use[i] = true;
continue;
}
auto it = prev(st.end());
int x = it->second;
st.erase(it);
has[x] = false;
has[c[i]] = true;
if (pos[c[i]].empty()) {
st.emplace(n, c[i]);
} else {
st.emplace(*pos[c[i]].begin(), c[i]);
}
}
vector<vector<int>> p(n);
for (int i = 0; i < n; i++) {
p[c[i]].push_back(i);
}
for (int i = 0; i < k; i++) {
if (pos[i].empty() || !use[p[i][0]]) {
WriteAdvice(0);
} else {
WriteAdvice(1);
}
}
vector<int> ptr(n);
for (int i = 0; i < n; i++) {
if (ptr[c[i]] == (int) p[c[i]].size() - 1) {
WriteAdvice(0);
} else {
WriteAdvice(use[p[c[i]][ptr[c[i]] + 1]] ? 1 : 0);
}
ptr[c[i]] += 1;
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
void Assist(unsigned char *a, int n, int k, int r) {
set<int> st;
for (int i = 0; i < k; i++) {
if (a[i] == 0) {
st.insert(i);
}
}
vector<bool> has(n);
for (int i = 0; i < k; i++) {
has[i] = true;
}
for (int i = 0; i < n; i++) {
int req = GetRequest();
if (!has[req]) {
has[req] = true;
PutBack(*st.begin());
has[*st.begin()] = false;
st.erase(st.begin());
}
if (a[k + i] == 0) {
st.insert(req);
}
}
}
/*
4 2 65000
2 0 3 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
512 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 |
2108 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
13616 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1284 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
110 ms |
16524 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
86 ms |
16688 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
100 ms |
17080 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
88 ms |
17172 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
87 ms |
16956 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
85 ms |
17044 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
87 ms |
16960 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
97 ms |
16960 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
115 ms |
16968 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
81 ms |
15744 KB |
Output isn't correct - not an optimal way |