Submission #337576

# Submission time Handle Problem Language Result Execution time Memory
337576 2020-12-21T06:49:21 Z seedkin 올림픽 피자 (tutorial5) C
Compilation error
0 ms 0 KB
#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 check() {
  for(int i =0; i < needCnt; i++) {
    if(material[need[i]] == 0) return 0;
  }
  return 1;
}

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(A, N);
  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;

  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

grader.c: In function 'main':
grader.c:65:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
tutorial5.c: In function 'check':
tutorial5.c:17:21: error: 'needCnt' undeclared (first use in this function)
   17 |   for(int i =0; i < needCnt; i++) {
      |                     ^~~~~~~
tutorial5.c:17:21: note: each undeclared identifier is reported only once for each function it appears in
tutorial5.c:18:17: error: 'need' undeclared (first use in this function)
   18 |     if(material[need[i]] == 0) return 0;
      |                 ^~~~
tutorial5.c: In function 'Order':
tutorial5.c:55:22: warning: passing argument 1 of 'makeMate' makes integer from pointer without a cast [-Wint-conversion]
   55 |   int idx = makeMate(A, N);
      |                      ^
      |                      |
      |                      int *
tutorial5.c:23:18: note: expected 'int' but argument is of type 'int *'
   23 | int makeMate(int N, int *A) {
      |              ~~~~^
tutorial5.c:55:25: warning: passing argument 2 of 'makeMate' makes pointer from integer without a cast [-Wint-conversion]
   55 |   int idx = makeMate(A, N);
      |                         ^
      |                         |
      |                         int
tutorial5.c:23:26: note: expected 'int *' but argument is of type 'int'
   23 | int makeMate(int N, int *A) {
      |                     ~~~~~^
tutorial5.c:56:20: warning: self-comparison always evaluates to true [-Wtautological-compare]
   56 |   if(allMate & idx == idx) {
      |                    ^~
tutorial5.c:56:20: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   56 |   if(allMate & idx == idx) {
      |                ~~~~^~~~~~
tutorial5.c: In function 'Delivery':
tutorial5.c:95:20: warning: self-comparison always evaluates to false [-Wtautological-compare]
   95 |     if(allMate & i != i) continue;
      |                    ^~
tutorial5.c:95:20: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   95 |     if(allMate & i != i) continue;
      |                  ~~^~~~
tutorial5.c:102:3: warning: implicit declaration of function 'bake'; did you mean 'Bake'? [-Wimplicit-function-declaration]
  102 |   bake(targetNum);
      |   ^~~~
      |   Bake