#include "advisor.h"
#include<set>
#include<queue>
#include<vector>
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);
for (int i=0;i<N;i++) Q[C[i]].push(i);
for (int i=0;i<N;i++) Q[i].push(N);
vector<int> takeback(N, -1);
for (int i=0;i<N;i++){
Q[C[i]].pop();
if (scafold.count(C[i]) > 0) continue;
int besttime = -1;
int bestcolour = -1;
for (set<int>::iterator it = scafold.begin(); it != scafold.end(); it++){
int u = *it;
if (Q[u].empty() || Q[u].front() > besttime){
besttime = Q[u].empty() ? N : Q[u].front();
bestcolour = u;
}
}
scafold.erase(bestcolour);
scafold.insert(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 (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);
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) {
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 |
776 KB |
Output is correct |
2 |
Correct |
0 ms |
776 KB |
Output is correct |
3 |
Correct |
1 ms |
2072 KB |
Output is correct |
4 |
Runtime error |
6 ms |
8540 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
27968 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2521 ms |
110164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
11608 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2536 ms |
136712 KB |
Time limit exceeded |
2 |
Execution timed out |
2533 ms |
136640 KB |
Time limit exceeded |
3 |
Execution timed out |
2564 ms |
136788 KB |
Time limit exceeded |
4 |
Execution timed out |
2565 ms |
136788 KB |
Time limit exceeded |
5 |
Execution timed out |
2575 ms |
136788 KB |
Time limit exceeded |
6 |
Execution timed out |
2533 ms |
136988 KB |
Time limit exceeded |
7 |
Execution timed out |
2573 ms |
136580 KB |
Time limit exceeded |
8 |
Execution timed out |
2559 ms |
137008 KB |
Time limit exceeded |
9 |
Execution timed out |
2550 ms |
136988 KB |
Time limit exceeded |
10 |
Execution timed out |
2556 ms |
136972 KB |
Time limit exceeded |