답안 #337583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337583 2020-12-21T06:57:26 Z seedkin 올림픽 피자 (tutorial5) C
100 / 100
78 ms 3436 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];
    }
  }
  if (targetNum == 1e8) return;
  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 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 5 ms 492 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2156 KB Output is correct
2 Correct 47 ms 2796 KB Output is correct
3 Correct 40 ms 2028 KB Output is correct
4 Correct 48 ms 2816 KB Output is correct
5 Correct 51 ms 3044 KB Output is correct
6 Correct 48 ms 3052 KB Output is correct
7 Correct 38 ms 1772 KB Output is correct
8 Correct 48 ms 3052 KB Output is correct
9 Correct 45 ms 2540 KB Output is correct
10 Correct 37 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 3308 KB Output is correct
2 Correct 76 ms 3308 KB Output is correct
3 Correct 76 ms 3308 KB Output is correct
4 Correct 78 ms 3436 KB Output is correct
5 Correct 76 ms 3308 KB Output is correct
6 Correct 76 ms 3308 KB Output is correct
7 Correct 76 ms 3308 KB Output is correct
8 Correct 77 ms 3308 KB Output is correct
9 Correct 78 ms 3308 KB Output is correct
10 Correct 78 ms 3436 KB Output is correct