Submission #336900

# Submission time Handle Problem Language Result Execution time Memory
336900 2020-12-17T08:04:08 Z seedkin 올림픽 피자 (tutorial5) C
20 / 100
1000 ms 4972 KB
#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) {    
    int r = check(order[cur].need, order[cur].needCnt);
    if(r || order[cur].live == 0) {
      if(r) {
        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];
    }
    if(material[I] == 0) return;
    cur = order[cur].next[I];
  }

}

Compilation message

grader.c: In function 'main':
grader.c:65:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 3052 KB Output is correct
2 Correct 49 ms 4204 KB Output is correct
3 Correct 41 ms 2796 KB Output is correct
4 Correct 48 ms 4460 KB Output is correct
5 Correct 50 ms 4972 KB Output is correct
6 Correct 51 ms 4972 KB Output is correct
7 Correct 38 ms 2156 KB Output is correct
8 Correct 52 ms 4844 KB Output is correct
9 Correct 46 ms 3852 KB Output is correct
10 Correct 38 ms 2024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1099 ms 2412 KB Time limit exceeded
2 Halted 0 ms 0 KB -