#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.push_back(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.push_back(req);
current[req] = true;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5360 KB |
Output is correct |
2 |
Correct |
7 ms |
5552 KB |
Output is correct |
3 |
Correct |
10 ms |
6056 KB |
Output is correct |
4 |
Correct |
11 ms |
6056 KB |
Output is correct |
5 |
Correct |
12 ms |
6208 KB |
Output is correct |
6 |
Incorrect |
10 ms |
6272 KB |
Error - advice is too long |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
343 ms |
10528 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2566 ms |
6724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
13448 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2541 ms |
7260 KB |
Time limit exceeded |
2 |
Execution timed out |
2567 ms |
7264 KB |
Time limit exceeded |
3 |
Execution timed out |
2566 ms |
7456 KB |
Time limit exceeded |
4 |
Execution timed out |
2573 ms |
7616 KB |
Time limit exceeded |
5 |
Execution timed out |
2576 ms |
7616 KB |
Time limit exceeded |
6 |
Execution timed out |
2567 ms |
7616 KB |
Time limit exceeded |
7 |
Execution timed out |
2557 ms |
7616 KB |
Time limit exceeded |
8 |
Execution timed out |
2538 ms |
7648 KB |
Time limit exceeded |
9 |
Execution timed out |
2567 ms |
7648 KB |
Time limit exceeded |
10 |
Execution timed out |
2562 ms |
8528 KB |
Time limit exceeded |