답안 #45439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45439 2018-04-14T01:41:22 Z tjd229 최후의 만찬 (IOI12_supper) C++11
0 / 100
108 ms 7136 KB
#include "advisor.h"
int sz=1;
struct NUse{
	int ix;
	int nxt;
	bool operator<(NUse &nu) const{
		return nxt < nu.nxt;
	}
}q[125001];
void swap(int &a, int &b){ a ^= b ^= a ^= b; }
void push(NUse nu){
	q[sz] = nu;
	int curr = sz++;
	while (curr != 1){
		if (q[curr>>1] < q[curr]){
			swap(q[curr].ix, q[curr >> 1].ix);
			swap(q[curr].nxt, q[curr >> 1].nxt);
		}
		else break;
		curr >>= 1;
	}
}
void pop(){
	q[1] = q[--sz];
	int curr = 1;
	int nxt = 2;
	while (nxt < sz){		
		if (nxt + 1 < sz && q[nxt] < q[1+nxt])
			nxt++;
		if (q[curr] < q[nxt]){
			swap(q[curr].ix, q[nxt].ix);
			swap(q[curr].nxt, q[nxt].nxt);
			curr = nxt;
			nxt += nxt;
		}
		else break;
	}
}
void ComputeAdvice(int *C, int N, int K, int M) {
	int nxt[100000] = { 0 };
	bool inq[100000] = { 0 };
	int right[100000];
	int future=0;
	int i;
	for (i = 0; i < N; i++) right[i] = 100001;
	for (i = N - 1; i >= 0; --i){
		nxt[i] = right[C[i]];
		right[C[i]] = i;
	}	
	for (i = 0; i < K; i++) push({ i, right[i] }), inq[i] = 1;
	future = q[1].nxt;
	for (i = 0; i < K; i++) WriteAdvice(right[i]!=future);
	for (i = 0; i < N; i++){
		while (!inq[q[1].ix]) pop();
		if (!inq[C[i]]){
			inq[q[1].ix] = 0;
			pop();
		}
		push({ C[i], nxt[i] });
		inq[C[i]] = 1;
		WriteAdvice(q[1].ix != C[i]);
						

	}

	/*WriteAdvice(0);
	WriteAdvice(1);
	WriteAdvice(2);*/

}
#include "assistant.h"
struct Heap{
	int sz = 0;
	int p[125001];
	int ix[125001];
	void swap(int &a, int &b){ a ^= b ^= a ^= b; }
	void push(int _p, int _ix){
		p[sz] = _p;
		ix[sz] = _ix;
		int curr = sz++;
		while (curr != 1 && p[curr] < p[curr >> 1]){
			swap(p[curr], p[curr >> 1]);
			swap(ix[curr], ix[curr >> 1]);
			curr >>= 1;
		}		
	}
	void pop(){
		p[1] = p[--sz];
		ix[1] = ix[sz];
		int curr = 1;
		int nxt = 2;
		while (nxt < sz){
			if (nxt + 1 < sz&&p[nxt] > p[nxt + 1]) nxt++;
			if (p[curr]>p[nxt]){
				swap(p[nxt], p[curr]);
				swap(ix[nxt], ix[curr]);
				curr = nxt;
				nxt += nxt;
			}
			else break;
		}
	}
}pq;
void Assist(unsigned char *A, int N, int K, int R) {

	int i;
	int a_ix = 0;
	bool inq[100000] = { 0 };
	for (i = 0; i < K; i++){
		pq.push(A[a_ix++],i);
		inq[i] = 1;
	}
	for (i = 0; i < N; i++){
		int req = GetRequest();
		while (!inq[pq.ix[1]]) pq.pop();
		if (!inq[req]){
			PutBack(pq.ix[1]);
			inq[pq.ix[1]] = 0;
			pq.pop();
		}
		pq.push(A[a_ix++],req);
		inq[req] = 1;
	}



}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1520 KB Output is correct
2 Incorrect 4 ms 1744 KB Output isn't correct - not an optimal way
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 2296 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 5688 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 5688 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 83 ms 6696 KB Output isn't correct - not an optimal way
2 Incorrect 78 ms 6856 KB Output isn't correct - not an optimal way
3 Incorrect 80 ms 6856 KB Output isn't correct - not an optimal way
4 Incorrect 80 ms 6856 KB Output isn't correct - not an optimal way
5 Incorrect 82 ms 6856 KB Output isn't correct - not an optimal way
6 Incorrect 81 ms 7008 KB Output isn't correct - not an optimal way
7 Incorrect 108 ms 7008 KB Output isn't correct - not an optimal way
8 Incorrect 82 ms 7048 KB Output isn't correct - not an optimal way
9 Incorrect 81 ms 7136 KB Output isn't correct - not an optimal way
10 Incorrect 76 ms 7136 KB Output isn't correct - not an optimal way