# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337580 | seedkin | 올림픽 피자 (tutorial5) | C11 | 1 ms | 364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "pizza.h"
struct Order {
int next;
int needCnt;
int need[8];
};
int order_num;
int material[8];
int allMate;
struct Order order[100000];
int root[256];
int last[256];
int makeMate(int N, int *A) {
int r = 0;
for(int i =0;i < N; i++) {
r |= (1 << A[i]);
}
return r;
}
void mergeMate() {
int r = 0;
for(int i =0 ;i < 8; i++) {
if(material[i]) r |= (1 << i);
}
allMate = r;
}
void Init() {
order_num = 0;
for(int i =0; i < 256; i ++) {
root[i] = -1;
last[i] = -1;
}
allMate = 0;
for(int i = 0; i < 8; i++) {
material[i] = 0;
}
}
void Order(int N, int *A) {
int idx = makeMate(N, A);
if( (allMate & idx) == idx) {
Bake(order_num);
order_num++;
for(int i =0; i < N; i++) {
material[A[i]]--;
}
mergeMate();
return;
}
order[order_num].needCnt = N;
for(int i =0; i < N; i++) {
order[order_num].need[i] = A[i];
}
order[order_num].next = -1;
if(root[idx] == -1) {
root[idx] = order_num;
last[idx] = order_num;
order_num++;
return;
}
order[last[idx]].next = order_num;
last[idx] = order_num;
order_num++;
return;
}
void Delivery(int I) {
material[I]++;
if(material[I] > 1) return;
mergeMate();
int targetNum = 1e8;
int targetMate = 0;
for(int i = 0; i < 256; i++) {
if(root[i] == -1) continue;
if( (allMate & i) != i) continue;
if(targetNum > root[i] ) {
targetMate = i;
targetNum = root[i];
}
}
Bake(targetNum);
root[targetMate] = order[targetNum].next;
for(int i =0; i< order[targetNum].needCnt; i++) {
material[order[targetNum].need[i]]--;
}
mergeMate();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |