답안 #337580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337580 2020-12-21T06:52:07 Z seedkin 올림픽 피자 (tutorial5) C
0 / 100
1 ms 364 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 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

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 Runtime error 1 ms 364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -