답안 #18580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18580 2016-02-09T14:51:34 Z jjhstop 올림픽 피자 (tutorial5) C++
100 / 100
151 ms 1732 KB
#include "pizza.h"
#include <queue>

using namespace std;

queue<int> Q[256];
int order_num;
int ingred[9];
int delivered;

void Init() {
	order_num = 0;

}

void Order(int N, int *A) {
	int ordering = 0;
	for (int i = 0; i < N; i++) {
		ordering |= (1 << A[i]);
	}
	if ((ordering & delivered) == ordering) {
		Bake(order_num);
		for (int i = 0; i < 8; i++) {
			if (ordering & (1 << i)) {
				ingred[i]--;
				if (ingred[i] == 0) delivered ^= (1 << i);
			}
		}
	}
	else {
		Q[ordering].push(order_num);
	}
	order_num++;
}

int check(int a)
{
	for (int i = 0; i< 8; ++i) {
		if (((a >> i) & 1) && (ingred[i] == 0)) return 0;
	}
	return 1;
}


void Delivery(int i) {
	ingred[i]++;
	if (ingred[i] == 1) {
		delivered |= (1 << i);
	}
	
	int minIdx = -1;
	int min = 99999;
	for (int i = 0; i < 256; i++) {
		if (!Q[i].empty() && check(i)) {
			if (Q[i].front() < min) {
				min = Q[i].front();
				minIdx = i;
			}
		}
	}
	if (minIdx != -1) {
		Bake(Q[minIdx].front());
		Q[minIdx].pop();
		for (int i = 0; i < 8; i++) {
			if (minIdx & (1 << i)) {
				ingred[i]--;
				if (ingred[i] == 0) delivered ^= (1 << i);
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1732 KB Output is correct
2 Correct 0 ms 1732 KB Output is correct
3 Correct 0 ms 1732 KB Output is correct
4 Correct 0 ms 1732 KB Output is correct
5 Correct 0 ms 1732 KB Output is correct
6 Correct 0 ms 1732 KB Output is correct
7 Correct 0 ms 1732 KB Output is correct
8 Correct 0 ms 1732 KB Output is correct
9 Correct 1 ms 1732 KB Output is correct
10 Correct 0 ms 1732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1732 KB Output is correct
2 Correct 7 ms 1732 KB Output is correct
3 Correct 5 ms 1732 KB Output is correct
4 Correct 4 ms 1732 KB Output is correct
5 Correct 7 ms 1732 KB Output is correct
6 Correct 9 ms 1732 KB Output is correct
7 Correct 7 ms 1732 KB Output is correct
8 Correct 7 ms 1732 KB Output is correct
9 Correct 3 ms 1732 KB Output is correct
10 Correct 7 ms 1732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 1732 KB Output is correct
2 Correct 58 ms 1732 KB Output is correct
3 Correct 64 ms 1732 KB Output is correct
4 Correct 48 ms 1732 KB Output is correct
5 Correct 67 ms 1732 KB Output is correct
6 Correct 54 ms 1732 KB Output is correct
7 Correct 58 ms 1732 KB Output is correct
8 Correct 66 ms 1732 KB Output is correct
9 Correct 66 ms 1732 KB Output is correct
10 Correct 59 ms 1732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 1732 KB Output is correct
2 Correct 144 ms 1732 KB Output is correct
3 Correct 145 ms 1732 KB Output is correct
4 Correct 147 ms 1732 KB Output is correct
5 Correct 143 ms 1732 KB Output is correct
6 Correct 136 ms 1732 KB Output is correct
7 Correct 147 ms 1732 KB Output is correct
8 Correct 129 ms 1732 KB Output is correct
9 Correct 133 ms 1732 KB Output is correct
10 Correct 151 ms 1732 KB Output is correct