Submission #45438

# Submission time Handle Problem Language Result Execution time Memory
45438 2018-04-14T01:33:41 Z tjd229 Last supper (IOI12_supper) C++11
0 / 100
102 ms 19232 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();
		if (!inq[req]){
			PutBack(pq.ix[1]);
			inq[pq.ix[1]] = 0;
			pq.pop();
		}
		pq.push(A[a_ix++],req);
		inq[req] = 1;
	}



}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 2616 KB Error - Putting back a color that is not on the scaffold
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 7088 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 7088 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 9120 KB Error - Putting back a color that is not on the scaffold
2 Incorrect 102 ms 10408 KB Output isn't correct - not an optimal way
3 Incorrect 77 ms 11560 KB Output isn't correct - not an optimal way
4 Incorrect 90 ms 12712 KB Output isn't correct - not an optimal way
5 Incorrect 88 ms 13944 KB Error - Putting back a color that is not on the scaffold
6 Incorrect 90 ms 15096 KB Output isn't correct - not an optimal way
7 Incorrect 80 ms 16288 KB Error - Putting back a color that is not on the scaffold
8 Incorrect 95 ms 17696 KB Output isn't correct - not an optimal way
9 Incorrect 77 ms 18592 KB Output isn't correct - not an optimal way
10 Incorrect 75 ms 19232 KB Output isn't correct - not an optimal way