답안 #336892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336892 2020-12-17T07:38:43 Z seedkin 올림픽 피자 (tutorial5) C
70 / 100
1000 ms 8044 KB
#include "pizza.h"

struct Order {
  int next;
  int prev;
  int need[8];
  int needCnt;
  int c[8];
};

int order_num;
int material[8];
struct Order order[100000];
int root = -1;
int last = -1;

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;
  root = -1;
  last = -1;
  for(int i = 0; i < 8; i++) {
    material[i] = 0;
  }

  for(int i =0; i< 100000; i++) {
    for(int j =0; j < 8; j++) {
      order[i].c[j] = 0;
    }
  }
}

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;
  for(int i =0; i < N; i++) {
    order[order_num].need[i] = A[i];
    order[order_num].c[A[i]] = 1;
  }
  order[order_num].next = -1;
  order[order_num].prev = -1;

  if(root == -1) {
    root = order_num;
    last = order_num;
    order_num++;
    return;
  }

  order[last].next = order_num;
  order[order_num].prev = last;
  last = order_num;
  order_num++;
  return;
}

void Delivery(int I) {
  material[I]++;

  if(root == -1) return;
  if(material[I] > 1) return;
  
  int cur = root;
  while(cur != -1) {
    if(order[cur].c[I] == 0) {
      cur = order[cur].next;
      continue;
    }
    int r = check(order[cur].need, order[cur].needCnt);
    if(r) {
      Bake(cur);      
      for(int i =0; i < order[cur].needCnt; i++) {
        material[order[cur].need[i]]--;
      }

      if(cur == root) {
        root = order[cur].next;
        if( root != -1) order[root].prev = -1;
        cur = root;
        continue;
      } 
      if ( cur == last) {
        last = order[cur].prev;
        if(last != -1) order[last].next = -1;        
        break;
      }

      order[order[cur].prev].next = order[cur].next;
      order[order[cur].next].prev = order[cur].prev;
    }
    if(material[I] == 0) return;
    cur = order[cur].next;
  }

}

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]
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7788 KB Output is correct
2 Correct 5 ms 7788 KB Output is correct
3 Correct 5 ms 7788 KB Output is correct
4 Correct 5 ms 7808 KB Output is correct
5 Correct 5 ms 7788 KB Output is correct
6 Correct 5 ms 7788 KB Output is correct
7 Correct 5 ms 7788 KB Output is correct
8 Correct 5 ms 7916 KB Output is correct
9 Correct 5 ms 7788 KB Output is correct
10 Correct 5 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 7788 KB Output is correct
2 Correct 23 ms 7788 KB Output is correct
3 Correct 23 ms 7788 KB Output is correct
4 Correct 23 ms 7788 KB Output is correct
5 Correct 23 ms 7916 KB Output is correct
6 Correct 23 ms 7788 KB Output is correct
7 Correct 23 ms 7788 KB Output is correct
8 Correct 22 ms 7808 KB Output is correct
9 Correct 22 ms 7916 KB Output is correct
10 Correct 23 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 7916 KB Output is correct
2 Correct 50 ms 7924 KB Output is correct
3 Correct 45 ms 7916 KB Output is correct
4 Correct 49 ms 7916 KB Output is correct
5 Correct 52 ms 7788 KB Output is correct
6 Correct 53 ms 7788 KB Output is correct
7 Correct 48 ms 7916 KB Output is correct
8 Correct 50 ms 7788 KB Output is correct
9 Correct 50 ms 7916 KB Output is correct
10 Correct 42 ms 8044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 7916 KB Time limit exceeded
2 Halted 0 ms 0 KB -