#include "advisor.h"
#include<set>
#include<queue>
#include<vector>
#include<assert.h>
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M) {
set<int> scafold;
for (int i=0;i<K;i++) scafold.insert(i);
vector<queue<int> > Q(N);
vector<queue<int> > returns(N);
vector<int> takeback(N, -1);
for (int i=0;i<N;i++) Q[C[i]].push(i);
for (int i=0;i<N;i++) Q[i].push(N);
priority_queue<pair<int,int> > next_use;
for (int i=0;i<K;i++) next_use.push(make_pair(Q[i].front(), i));
for (int i=0;i<N;i++){
Q[C[i]].pop();
if (scafold.count(C[i]) > 0) {
next_use.push(make_pair(Q[C[i]].front(), C[i]));
continue;
}
while (true){
if (scafold.count(next_use.top().second) == 0){
next_use.pop();
continue;
}
break;
}
int bestcolour = next_use.top().second;
next_use.pop();
scafold.erase(bestcolour);
scafold.insert(C[i]);
next_use.push(make_pair(Q[C[i]].front(),C[i]));
returns[bestcolour].push(i);
takeback[i] = bestcolour;
}
Q.assign(N, queue<int> ());
for (int i=0;i<N;i++) Q[C[i]].push(i);
for (int i=0;i<N;i++) Q[i].push(N);
for (int i=0;i<K;i++){
if (Q[i].empty()){
WriteAdvice(0);
continue;
}
if (returns[i].empty()){
WriteAdvice(1);
continue;
}
if (Q[i].front() <= returns[i].front()){
WriteAdvice(1);
} else WriteAdvice(0);
}
for (int i=0;i<N;i++){
Q[C[i]].pop();
if (takeback[i] != -1) returns[takeback[i]].pop();
if (Q[C[i]].empty()){
WriteAdvice(0);
continue;
}
if (returns[C[i]].empty()){
WriteAdvice(1);
continue;
}
if (Q[C[i]].front() <= returns[C[i]].front()){
WriteAdvice(1);
} else WriteAdvice(0);
}
}
#include "assistant.h"
#include<queue>
#include<set>
#include<assert.h>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
set<int> expendable,scafold;
for (int i=0;i<K;i++) if (A[i] == 0) expendable.insert(i);
for (int i=0;i<K;i++) scafold.insert(i);
for (int i=0;i<N;i++){
int req = GetRequest();
if (scafold.count(req) > 0){
if (A[K + i] == 0) expendable.insert(req);
continue;
}
PutBack(*expendable.begin());
scafold.erase(*expendable.begin());
expendable.erase(*expendable.begin());
scafold.insert(req);
if (A[K + i] == 0) expendable.insert(req);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
788 KB |
Output is correct |
2 |
Correct |
0 ms |
780 KB |
Output is correct |
3 |
Correct |
1 ms |
2072 KB |
Output is correct |
4 |
Correct |
4 ms |
4924 KB |
Output is correct |
5 |
Correct |
6 ms |
7496 KB |
Output is correct |
6 |
Correct |
8 ms |
7496 KB |
Output is correct |
7 |
Correct |
6 ms |
7760 KB |
Output is correct |
8 |
Correct |
7 ms |
7572 KB |
Output is correct |
9 |
Correct |
10 ms |
7756 KB |
Output is correct |
10 |
Correct |
8 ms |
7756 KB |
Output is correct |
11 |
Correct |
8 ms |
7604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
14972 KB |
Output is correct |
2 |
Correct |
91 ms |
70432 KB |
Output is correct |
3 |
Correct |
235 ms |
142256 KB |
Output is correct |
4 |
Correct |
179 ms |
137632 KB |
Output is correct |
5 |
Correct |
192 ms |
137628 KB |
Output is correct |
6 |
Correct |
207 ms |
139072 KB |
Output is correct |
7 |
Correct |
231 ms |
140660 KB |
Output is correct |
8 |
Correct |
190 ms |
119544 KB |
Output is correct |
9 |
Correct |
147 ms |
135116 KB |
Output is correct |
10 |
Correct |
219 ms |
141728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
113360 KB |
Output is correct |
2 |
Correct |
221 ms |
141180 KB |
Output is correct |
3 |
Correct |
219 ms |
141604 KB |
Output is correct |
4 |
Correct |
219 ms |
141572 KB |
Output is correct |
5 |
Correct |
197 ms |
139624 KB |
Output is correct |
6 |
Correct |
217 ms |
141424 KB |
Output is correct |
7 |
Correct |
210 ms |
141172 KB |
Output is correct |
8 |
Correct |
217 ms |
140620 KB |
Output is correct |
9 |
Correct |
179 ms |
141684 KB |
Output is correct |
10 |
Correct |
215 ms |
141176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6464 KB |
Output is correct |
2 |
Correct |
7 ms |
7640 KB |
Output is correct |
3 |
Correct |
6 ms |
7508 KB |
Output is correct |
4 |
Correct |
6 ms |
7504 KB |
Output is correct |
5 |
Correct |
8 ms |
7568 KB |
Output is correct |
6 |
Correct |
8 ms |
7492 KB |
Output is correct |
7 |
Correct |
10 ms |
7756 KB |
Output is correct |
8 |
Correct |
10 ms |
7932 KB |
Output is correct |
9 |
Correct |
8 ms |
7756 KB |
Output is correct |
10 |
Correct |
8 ms |
8016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
140840 KB |
Output is correct - 120000 bits used |
2 |
Correct |
227 ms |
141192 KB |
Output is correct - 122000 bits used |
3 |
Correct |
219 ms |
141164 KB |
Output is correct - 125000 bits used |
4 |
Correct |
221 ms |
141440 KB |
Output is correct - 125000 bits used |
5 |
Correct |
228 ms |
141172 KB |
Output is correct - 125000 bits used |
6 |
Correct |
216 ms |
141172 KB |
Output is correct - 125000 bits used |
7 |
Correct |
215 ms |
141196 KB |
Output is correct - 124828 bits used |
8 |
Correct |
219 ms |
141328 KB |
Output is correct - 124910 bits used |
9 |
Correct |
254 ms |
141416 KB |
Output is correct - 125000 bits used |
10 |
Correct |
220 ms |
140576 KB |
Output is correct - 125000 bits used |