Submission #45440

# Submission time Handle Problem Language Result Execution time Memory
45440 2018-04-14T02:36:42 Z tjd229 Last supper (IOI12_supper) C++11
91 / 100
148 ms 27432 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 left[100000];
	int a[125001] = { 0 };
	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, left[i]=i;
	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]]){
			a[ left[q[1].ix] ] = 1;
			inq[q[1].ix] = 0;
			pop();
		}
		push({ C[i], nxt[i] });
		inq[C[i]] = 1;
		left[C[i]] = K+i;
	}
	for (i = 0; i < N + K; i++) WriteAdvice(a[i]^1);

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

}
#include "assistant.h"
struct Heap{
	int sz = 1;
	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;
	}



}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:46:6: warning: variable 'future' set but not used [-Wunused-but-set-variable]
  int future=0;
      ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2544 KB Output is correct
2 Correct 4 ms 2760 KB Output is correct
3 Correct 5 ms 3168 KB Output is correct
4 Correct 6 ms 3424 KB Output is correct
5 Correct 7 ms 3624 KB Output is correct
6 Correct 8 ms 3704 KB Output is correct
7 Correct 10 ms 3752 KB Output is correct
8 Correct 8 ms 3832 KB Output is correct
9 Correct 11 ms 3880 KB Output is correct
10 Correct 10 ms 3928 KB Output is correct
11 Correct 8 ms 3984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4320 KB Output is correct
2 Correct 43 ms 7144 KB Output is correct
3 Runtime error 30 ms 7436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15592 KB Output is correct
2 Correct 88 ms 17800 KB Output is correct
3 Correct 84 ms 18952 KB Output is correct
4 Correct 85 ms 20168 KB Output is correct
5 Correct 84 ms 21256 KB Output is correct
6 Correct 84 ms 22400 KB Output is correct
7 Correct 148 ms 23592 KB Output is correct
8 Correct 86 ms 24224 KB Output is correct
9 Correct 84 ms 26224 KB Output is correct
10 Correct 104 ms 27296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 27296 KB Output is correct
2 Correct 9 ms 27296 KB Output is correct
3 Correct 9 ms 27296 KB Output is correct
4 Correct 7 ms 27296 KB Output is correct
5 Correct 7 ms 27296 KB Output is correct
6 Correct 8 ms 27296 KB Output is correct
7 Correct 10 ms 27296 KB Output is correct
8 Correct 9 ms 27296 KB Output is correct
9 Correct 12 ms 27296 KB Output is correct
10 Correct 10 ms 27296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 27344 KB Output is correct - 120000 bits used
2 Correct 83 ms 27344 KB Output is correct - 122000 bits used
3 Correct 94 ms 27344 KB Output is correct - 125000 bits used
4 Correct 130 ms 27344 KB Output is correct - 125000 bits used
5 Correct 113 ms 27344 KB Output is correct - 125000 bits used
6 Correct 85 ms 27344 KB Output is correct - 125000 bits used
7 Correct 84 ms 27360 KB Output is correct - 124828 bits used
8 Correct 86 ms 27360 KB Output is correct - 124910 bits used
9 Correct 92 ms 27432 KB Output is correct - 125000 bits used
10 Correct 131 ms 27432 KB Output is correct - 125000 bits used