#include "pizza.h"
#include <queue>
using namespace std;
queue<int> Q[256];
int order_num;
int ingred[9];
int delivered;
void Init() {
order_num = 0;
}
void process(void)
{
while (1) {
int chk = -1;
for (int i = delivered; i > 0; i = (i - 1) & delivered) {
if (!Q[i].empty() && (chk < 0 || Q[chk].front() > Q[i].front())) chk = i;
}
if (chk < 0) return;
Bake(Q[chk].front());
Q[chk].pop();
for (int i = 0; i < 8; i++) {
if (chk & (1 << i)) {
ingred[i]--;
if (ingred[i] == 0) delivered ^= (1 << i);
}
}
}
}
void Order(int N, int *A) {
int ordering = 0;
for (int i = 0; i < N; i++) {
ordering |= (1 << A[i]);
}
if ((ordering & delivered) == ordering) {
Bake(order_num);
for (int i = 0; i < 8; i++) {
if (ordering & (1 << i)) {
ingred[i]--;
if (ingred[i] == 0) delivered ^= (1 << i);
}
}
}
else {
Q[ordering].push(order_num);
}
order_num++;
}
void Delivery(int i) {
ingred[i]++;
if (ingred[i] == 1) {
delivered |= (1 << i);
}
process();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1732 KB |
Output is correct |
2 |
Correct |
0 ms |
1732 KB |
Output is correct |
3 |
Correct |
0 ms |
1732 KB |
Output is correct |
4 |
Correct |
0 ms |
1732 KB |
Output is correct |
5 |
Correct |
0 ms |
1732 KB |
Output is correct |
6 |
Correct |
0 ms |
1732 KB |
Output is correct |
7 |
Correct |
0 ms |
1732 KB |
Output is correct |
8 |
Correct |
0 ms |
1732 KB |
Output is correct |
9 |
Correct |
0 ms |
1732 KB |
Output is correct |
10 |
Correct |
0 ms |
1732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1732 KB |
Output is correct |
2 |
Correct |
3 ms |
1732 KB |
Output is correct |
3 |
Correct |
4 ms |
1732 KB |
Output is correct |
4 |
Correct |
0 ms |
1732 KB |
Output is correct |
5 |
Correct |
4 ms |
1732 KB |
Output is correct |
6 |
Correct |
0 ms |
1732 KB |
Output is correct |
7 |
Correct |
3 ms |
1732 KB |
Output is correct |
8 |
Correct |
0 ms |
1732 KB |
Output is correct |
9 |
Correct |
4 ms |
1732 KB |
Output is correct |
10 |
Correct |
3 ms |
1732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
1732 KB |
Output is correct |
2 |
Correct |
72 ms |
1732 KB |
Output is correct |
3 |
Correct |
72 ms |
1732 KB |
Output is correct |
4 |
Correct |
70 ms |
1732 KB |
Output is correct |
5 |
Correct |
75 ms |
1732 KB |
Output is correct |
6 |
Correct |
69 ms |
1732 KB |
Output is correct |
7 |
Correct |
75 ms |
1732 KB |
Output is correct |
8 |
Correct |
53 ms |
1732 KB |
Output is correct |
9 |
Correct |
74 ms |
1732 KB |
Output is correct |
10 |
Correct |
73 ms |
1732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
1732 KB |
Output is correct |
2 |
Correct |
70 ms |
1732 KB |
Output is correct |
3 |
Correct |
54 ms |
1732 KB |
Output is correct |
4 |
Correct |
63 ms |
1732 KB |
Output is correct |
5 |
Correct |
57 ms |
1732 KB |
Output is correct |
6 |
Correct |
33 ms |
1732 KB |
Output is correct |
7 |
Correct |
61 ms |
1732 KB |
Output is correct |
8 |
Correct |
54 ms |
1732 KB |
Output is correct |
9 |
Correct |
56 ms |
1732 KB |
Output is correct |
10 |
Correct |
47 ms |
1732 KB |
Output is correct |