#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> nxt[N];
bool chosen[N], rest[N];
void ComputeAdvice(int *C, int N, int K, int M) {
for(int i = N - 1; i >= 0; i--) nxt[C[i]].push_back(i);
priority_queue<pair<int, int> > Q;
for(int i = 0; i < K; i++) {
int tmp = nxt[i].empty() ? N : nxt[i].back();
Q.push({tmp, i});
chosen[i] = 1;
}
for(int i = 0; i < N; i++) {
int x = C[i];
nxt[x].pop_back();
while (!Q.empty() && chosen[Q.top().second] == 0) Q.pop();
if (chosen[x] == 0) {
int useless, j; tie(useless, j) = Q.top(); Q.pop();
chosen[j] = 0;
chosen[x] = 1;
int tmp = nxt[x].empty() ? N : nxt[x].back();
Q.push({tmp, x});
rest[i] = 0;
}
else {
Q.push({nxt[x].empty() ? N : nxt[x].back(), x});
rest[i] = 1;
}
}
for(int i = N - 1; i >= 0; i--) nxt[C[i]].push_back(i);
for(int i = 0; i < K; i++) {
int tmp = nxt[i].empty() ? N : nxt[i].back();
WriteAdvice(rest[tmp]);
}
for(int i = 0; i < N; i++) {
int x = C[i];
nxt[x].pop_back();
int tmp = nxt[x].empty() ? N : nxt[x].back();
WriteAdvice(rest[tmp]);
}
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool in[N];
void Assist(unsigned char *A, int N, int K, int R) {
int cnt = 0;
vector<int> useless;
for(int i = 0; i < K; i++) {
if (!int(A[cnt])) useless.push_back(i);
cnt++;
in[i] = 1;
}
for(int i = 0; i < N; i++) {
int x = GetRequest();
if (!in[x]) {
assert(useless.size());
int dog = useless.back(); useless.pop_back();
PutBack(dog);
in[dog] = 0;
}
in[x] = 1;
if (!int(A[cnt])) useless.push_back(x);
cnt++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3084 KB |
Output is correct |
2 |
Correct |
1 ms |
3088 KB |
Output is correct |
3 |
Correct |
1 ms |
3096 KB |
Output is correct |
4 |
Correct |
3 ms |
3116 KB |
Output is correct |
5 |
Correct |
3 ms |
3380 KB |
Output is correct |
6 |
Correct |
3 ms |
3380 KB |
Output is correct |
7 |
Correct |
4 ms |
3692 KB |
Output is correct |
8 |
Correct |
3 ms |
3380 KB |
Output is correct |
9 |
Correct |
4 ms |
3468 KB |
Output is correct |
10 |
Correct |
4 ms |
3384 KB |
Output is correct |
11 |
Correct |
4 ms |
3380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3692 KB |
Output is correct |
2 |
Correct |
26 ms |
5144 KB |
Output is correct |
3 |
Correct |
61 ms |
9620 KB |
Output is correct |
4 |
Correct |
48 ms |
8232 KB |
Output is correct |
5 |
Correct |
49 ms |
8148 KB |
Output is correct |
6 |
Correct |
52 ms |
8272 KB |
Output is correct |
7 |
Correct |
54 ms |
8916 KB |
Output is correct |
8 |
Correct |
45 ms |
8664 KB |
Output is correct |
9 |
Correct |
43 ms |
6940 KB |
Output is correct |
10 |
Correct |
55 ms |
8648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
7768 KB |
Output is correct |
2 |
Correct |
54 ms |
8400 KB |
Output is correct |
3 |
Correct |
55 ms |
10024 KB |
Output is correct |
4 |
Correct |
53 ms |
9752 KB |
Output is correct |
5 |
Correct |
55 ms |
8696 KB |
Output is correct |
6 |
Correct |
56 ms |
9768 KB |
Output is correct |
7 |
Correct |
57 ms |
9708 KB |
Output is correct |
8 |
Correct |
68 ms |
10820 KB |
Output is correct |
9 |
Correct |
50 ms |
8644 KB |
Output is correct |
10 |
Correct |
55 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3376 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3408 KB |
Output is correct |
5 |
Correct |
4 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
4 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
4 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
8308 KB |
Output is correct - 120000 bits used |
2 |
Correct |
56 ms |
8500 KB |
Output is correct - 122000 bits used |
3 |
Correct |
58 ms |
8696 KB |
Output is correct - 125000 bits used |
4 |
Correct |
54 ms |
8716 KB |
Output is correct - 125000 bits used |
5 |
Correct |
61 ms |
8572 KB |
Output is correct - 125000 bits used |
6 |
Correct |
56 ms |
8676 KB |
Output is correct - 125000 bits used |
7 |
Correct |
62 ms |
8608 KB |
Output is correct - 124828 bits used |
8 |
Correct |
61 ms |
8772 KB |
Output is correct - 124910 bits used |
9 |
Correct |
58 ms |
8660 KB |
Output is correct - 125000 bits used |
10 |
Correct |
51 ms |
9828 KB |
Output is correct - 125000 bits used |