#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++){
assert(Q[C[i]].front() == 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;
}
assert(next_use.top().first > i);
break;
}
if (K <= 5000){
int besttime = 0;
for (set<int>::iterator it = scafold.begin(); it != scafold.end(); it++){
assert(Q[*it].front() <= next_use.top().first);
besttime = max(besttime,Q[*it].front());
}
assert(besttime == next_use.top().first);
}
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++){
assert(Q[C[i]].front() == i);
Q[C[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);
if (takeback[i] != -1) returns[takeback[i]].pop();
}
}
#include "assistant.h"
#include<queue>
#include<set>
#include<assert.h>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
assert(R == N + K);
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;
}
assert(expendable.size() > 0);
PutBack(*expendable.begin());
scafold.erase(*expendable.begin());
expendable.erase(*expendable.begin());
scafold.insert(req);
if (A[K + i] == 0) expendable.insert(req);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
792 KB |
Output is correct |
2 |
Correct |
0 ms |
792 KB |
Output is correct |
3 |
Correct |
1 ms |
2072 KB |
Output is correct |
4 |
Correct |
4 ms |
4912 KB |
Output is correct |
5 |
Correct |
6 ms |
7508 KB |
Output is correct |
6 |
Correct |
10 ms |
7540 KB |
Output is correct |
7 |
Correct |
7 ms |
7748 KB |
Output is correct |
8 |
Correct |
22 ms |
7768 KB |
Output is correct |
9 |
Correct |
25 ms |
7728 KB |
Output is correct |
10 |
Correct |
27 ms |
7756 KB |
Output is correct |
11 |
Correct |
23 ms |
7656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
15140 KB |
Output is correct |
2 |
Incorrect |
1349 ms |
70712 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
113612 KB |
Output is correct |
2 |
Correct |
225 ms |
141144 KB |
Output is correct |
3 |
Correct |
217 ms |
141176 KB |
Output is correct |
4 |
Correct |
211 ms |
141392 KB |
Output is correct |
5 |
Incorrect |
185 ms |
139676 KB |
Output isn't correct - not an optimal way |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
6440 KB |
Output is correct |
2 |
Correct |
26 ms |
7792 KB |
Output is correct |
3 |
Incorrect |
9 ms |
7500 KB |
Output isn't correct - not an optimal way |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
213 ms |
140812 KB |
Output isn't correct - not an optimal way |
2 |
Correct |
226 ms |
141264 KB |
Output is correct - 122000 bits used |
3 |
Correct |
213 ms |
141232 KB |
Output is correct - 125000 bits used |
4 |
Correct |
210 ms |
141448 KB |
Output is correct - 125000 bits used |
5 |
Correct |
207 ms |
141164 KB |
Output is correct - 125000 bits used |
6 |
Correct |
214 ms |
141284 KB |
Output is correct - 125000 bits used |
7 |
Correct |
216 ms |
141088 KB |
Output is correct - 124828 bits used |
8 |
Correct |
216 ms |
141336 KB |
Output is correct - 124910 bits used |
9 |
Correct |
211 ms |
141332 KB |
Output is correct - 125000 bits used |
10 |
Correct |
240 ms |
140632 KB |
Output is correct - 125000 bits used |