#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
typedef pair<int,int> pii;
static vector<int> v[MAXN];
static bool current[MAXN];
static set<pii> nxRemove;
int getNextUsage(int i) {
if (v[i].empty()) return 1000000000;
else {
int ret = v[i].back();
return ret;
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i = 0; i < N; i++)
v[C[i]].push_back(i);
for (int i = 0; i < N; i++)
reverse(v[i].begin(), v[i].end());
for (int i = 0; i < N; i++) current[i] = false;
vector<int> stk;
for (int i = 0; i < K; i++) {
stk.push_back(i);
current[i] = true;
nxRemove.insert({getNextUsage(i), i});
}
for (int i = 0; i < N; i++) {
// printf("i %d C[i] %d\n", i, C[i]);
if (current[C[i]]) {
nxRemove.erase({getNextUsage(C[i]), C[i]});
v[C[i]].pop_back();
nxRemove.insert({getNextUsage(C[i]), C[i]});
} else {
auto it = prev(nxRemove.end());
int toRemove = it->second;
nxRemove.erase(it);
v[C[i]].pop_back();
nxRemove.insert({getNextUsage(C[i]), C[i]});
// printf("toRemove %d\n", toRemove);
while (stk.back() != toRemove) {
WriteAdvice(1);
// printf("putBit %d\n", 1);
int back = stk.back();
stk.pop_back();
stk.insert(stk.begin(), back);
}
WriteAdvice(0);
// printf("putBit %d\n", 0);
stk.pop_back();
stk.insert(stk.begin(), C[i]);
current[C[i]] = true;
current[toRemove] = false;
}
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
static bool current[MAXN];
vector<int> stk;
bool getBit(unsigned char *A) {
static int i = 0;
// printf("getBit %d\n", A[i]);
return A[i++];
}
void Assist(unsigned char *A, int N, int K, int R) {
for (int i = 0; i < K; i++) {
stk.push_back(i);
current[i] = true;
}
for (int i = 0; i < N; i++) {
int req = GetRequest();
if (current[req]) {
continue;
}
while (getBit(A)) {
int back = stk.back();
stk.pop_back();
stk.insert(stk.begin(), back);
}
PutBack(stk.back());
current[stk.back()] = false;
stk.pop_back();
stk.insert(stk.begin(), req);
current[req] = true;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5360 KB |
Output is correct |
2 |
Correct |
6 ms |
5576 KB |
Output is correct |
3 |
Correct |
7 ms |
5864 KB |
Output is correct |
4 |
Correct |
10 ms |
6056 KB |
Output is correct |
5 |
Correct |
11 ms |
6056 KB |
Output is correct |
6 |
Incorrect |
10 ms |
6080 KB |
Error - advice is too long |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
406 ms |
10472 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2515 ms |
6716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
13432 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2535 ms |
7240 KB |
Time limit exceeded |
2 |
Execution timed out |
2563 ms |
7240 KB |
Time limit exceeded |
3 |
Execution timed out |
2530 ms |
7268 KB |
Time limit exceeded |
4 |
Execution timed out |
2546 ms |
7556 KB |
Time limit exceeded |
5 |
Execution timed out |
2552 ms |
7556 KB |
Time limit exceeded |
6 |
Execution timed out |
2554 ms |
7556 KB |
Time limit exceeded |
7 |
Execution timed out |
2564 ms |
7556 KB |
Time limit exceeded |
8 |
Execution timed out |
2551 ms |
7556 KB |
Time limit exceeded |
9 |
Execution timed out |
2527 ms |
7556 KB |
Time limit exceeded |
10 |
Execution timed out |
2547 ms |
8352 KB |
Time limit exceeded |