# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336908 | seedkin | 올림픽 피자 (tutorial5) | C11 | 1084 ms | 4972 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[8];
int prev[8];
int need[8];
int needCnt;
int live;
};
int order_num;
int material[8];
struct Order order[100000];
int root[8];
int last[8];
int check(int need[8], int needCnt) {
for(int i =0; i< needCnt; i++) {
if(material[need[i]] == 0) return 0;
}
return 1;
}
void Init() {
order_num = 0;
for(int i = 0; i < 8; i++) {
material[i] = 0;
root[i] = -1;
last[i] = -1;
}
}
void Order(int N, int *A) {
int r = check(A, N);
if(r) {
Bake(order_num);
order_num++;
for(int i =0; i < N; i++) {
material[A[i]]--;
}
return;
}
order[order_num].needCnt = N;
order[order_num].live = 1;
for(int i =0; i < N; i++) {
order[order_num].need[i] = A[i];
}
for(int i = 0; i< 8; i++) {
order[order_num].next[i] = -1;
order[order_num].prev[i] = -1;
}
for(int i =0; i < N; i++) {
int idx = A[i];
if(root[idx] == -1) {
root[idx] = order_num;
last[idx] = order_num;
continue;
}
order[last[idx]].next[idx] = order_num;
order[order_num].prev[idx] = last[idx];
last[idx] = order_num;
}
order_num++;
return;
}
void Delivery(int I) {
material[I]++;
if(root[I] == -1) return;
if(material[I] > 1) return;
int cur = root[I];
while(cur != -1) {
if(material[I] == 0) return;
int r = check(order[cur].need, order[cur].needCnt);
if(r || order[cur].live == 0) {
if(r && order[cur].live) {
Bake(cur);
order[cur].live = 0;
for(int i =0; i < order[cur].needCnt; i++) {
material[order[cur].need[i]]--;
}
}
if(cur == root[I]) {
root[I] = order[cur].next[I];
if( root[I] != -1) order[root[I]].prev[I] = -1;
cur = root[I];
continue;
}
if ( cur == last[I]) {
last[I] = order[cur].prev[I];
if(last[I] != -1) order[last[I]].next[I] = -1;
break;
}
order[order[cur].prev[I]].next[I] = order[cur].next[I];
order[order[cur].next[I]].prev[I] = order[cur].prev[I];
}
cur = order[cur].next[I];
}
}
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... |