#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100025;
vector<int> last[maxn];
int scaffold[maxn];
int onScaffold[maxn];
int tt[maxn];
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i = 0; i < K; i++)
scaffold[i] = i, onScaffold[i] = i;
for (int i = K; i < N; i++)
onScaffold[i] = -1;
for (int i = 0; i < N; i++)
last[i].push_back(maxn);
for (int i = N-1; i >= 0; i--)
last[C[i]].push_back(i);
set<pair<int,int>> st;
for (int i = 0; i < K; i++)
st.insert({ -last[i].back(), i }), tt[i] = i;
vector<bool> garbage(N + K);
for (int i = 0; i < N; i++) {
int req = C[i];
if (onScaffold[req] == -1) {
last[C[i]].pop_back();
int pos = st.begin() -> second;
garbage[tt[pos]] = true;
st.erase(st.begin());
onScaffold[req] = pos;
onScaffold[scaffold[pos]] = -1;
scaffold[pos] = req;
tt[pos] = i + K;
st.insert({ -last[C[i]].back(), pos });
} else {
int pos = onScaffold[C[i]];
st.erase({ -last[C[i]].back(), pos });
last[C[i]].pop_back();
tt[pos] = i + K;
st.insert({ -last[C[i]].back(), pos });
}
}
for (int i = 0; i < N+K; i++)
WriteAdvice(garbage[i]);
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100025;
int scaffold[maxn];
int onScaffold[maxn];
void Assist(unsigned char *A, int N, int K, int R) {
std::queue<int> q;
for (int i = 0; i < K; i++) {
onScaffold[i] = i;
scaffold[i] = i;
if (A[i])
q.push(i);
}
for (int i = K; i < N; i++)
onScaffold[i] = -1;
for (int i = 0; i < N; i++) {
int r = GetRequest();
if (onScaffold[r] == -1) {
int pos = q.front(); q.pop();
onScaffold[scaffold[pos]] = -1;
onScaffold[r] = pos;
PutBack(scaffold[pos]);
scaffold[pos] = r;
}
if (A[i+K])
q.push(onScaffold[r]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3224 KB |
Output is correct |
2 |
Correct |
2 ms |
3044 KB |
Output is correct |
3 |
Correct |
4 ms |
3308 KB |
Output is correct |
4 |
Correct |
5 ms |
3336 KB |
Output is correct |
5 |
Correct |
7 ms |
3720 KB |
Output is correct |
6 |
Correct |
6 ms |
3336 KB |
Output is correct |
7 |
Correct |
7 ms |
3488 KB |
Output is correct |
8 |
Correct |
7 ms |
3464 KB |
Output is correct |
9 |
Correct |
7 ms |
3660 KB |
Output is correct |
10 |
Correct |
8 ms |
3684 KB |
Output is correct |
11 |
Correct |
8 ms |
3464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4124 KB |
Output is correct |
2 |
Correct |
56 ms |
6916 KB |
Output is correct |
3 |
Correct |
141 ms |
11984 KB |
Output is correct |
4 |
Correct |
95 ms |
9740 KB |
Output is correct |
5 |
Correct |
100 ms |
9864 KB |
Output is correct |
6 |
Correct |
115 ms |
10312 KB |
Output is correct |
7 |
Correct |
140 ms |
11060 KB |
Output is correct |
8 |
Correct |
108 ms |
10384 KB |
Output is correct |
9 |
Correct |
81 ms |
10364 KB |
Output is correct |
10 |
Correct |
144 ms |
11920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
9876 KB |
Output is correct |
2 |
Correct |
149 ms |
11792 KB |
Output is correct |
3 |
Correct |
138 ms |
11584 KB |
Output is correct |
4 |
Correct |
142 ms |
11648 KB |
Output is correct |
5 |
Correct |
136 ms |
11564 KB |
Output is correct |
6 |
Correct |
142 ms |
11684 KB |
Output is correct |
7 |
Correct |
140 ms |
11452 KB |
Output is correct |
8 |
Correct |
127 ms |
11380 KB |
Output is correct |
9 |
Correct |
120 ms |
12092 KB |
Output is correct |
10 |
Correct |
142 ms |
11696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3460 KB |
Output is correct |
2 |
Correct |
7 ms |
3476 KB |
Output is correct |
3 |
Correct |
7 ms |
3336 KB |
Output is correct |
4 |
Correct |
6 ms |
3336 KB |
Output is correct |
5 |
Correct |
7 ms |
3336 KB |
Output is correct |
6 |
Correct |
7 ms |
3464 KB |
Output is correct |
7 |
Correct |
7 ms |
3336 KB |
Output is correct |
8 |
Correct |
8 ms |
3484 KB |
Output is correct |
9 |
Correct |
8 ms |
3464 KB |
Output is correct |
10 |
Correct |
9 ms |
3728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
11060 KB |
Output is correct - 120000 bits used |
2 |
Correct |
138 ms |
11372 KB |
Output is correct - 122000 bits used |
3 |
Correct |
139 ms |
11452 KB |
Output is correct - 125000 bits used |
4 |
Correct |
142 ms |
11684 KB |
Output is correct - 125000 bits used |
5 |
Correct |
139 ms |
11452 KB |
Output is correct - 125000 bits used |
6 |
Correct |
143 ms |
11660 KB |
Output is correct - 125000 bits used |
7 |
Correct |
139 ms |
11632 KB |
Output is correct - 124828 bits used |
8 |
Correct |
143 ms |
11552 KB |
Output is correct - 124910 bits used |
9 |
Correct |
142 ms |
11624 KB |
Output is correct - 125000 bits used |
10 |
Correct |
133 ms |
11408 KB |
Output is correct - 125000 bits used |