Submission #241741

# Submission time Handle Problem Language Result Execution time Memory
241741 2020-06-25T12:10:05 Z kshitij_sodani Last supper (IOI12_supper) C++17
0 / 100
2500 ms 63472 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second

#include "advisor.h"
//void WriteAdvice(int x);
vector<int> ind[1000001];
int ans[2000001];
set<int> cur;
int prev2[2000001];
/*void WriteAdvice(int x){
	cout<<x<<endl;
}
*/
void ComputeAdvice(int c[], int n, int k, int m) {
	set<pair<int,int>> kk;
	for(int i=0;i<n;i++){
		ind[c[i]].pb(i);
	}
	for(int i=0;i<n;i++){
		ind[i].pb(n+1);
	}
	for(int i=0;i<k;i++){
		kk.insert({ind[i][0],i});
		prev2[i]=i;
		cur.insert(i);
	}

	for(int i=0;i<n;i++){
		if(cur.find(c[i])!=cur.end()){

			kk.erase({i,prev2[c[i]]});
			prev2[c[i]]=i+k;
			int j=upper_bound(ind[c[i]].begin(),ind[c[i]].end(),i)-ind[c[i]].begin();
			kk.insert({ind[c[i]][j],i+k});
			continue;
		}
		auto j=kk.end();
		j--;
		ans[(*j).b]=1;
		if((*j).b>=k){
			cur.erase(c[(*j).b-k]);
		}
		else{
			cur.erase((*j).b);
		}
		cur.insert(c[i]);
		kk.erase(j);
		int jj=upper_bound(ind[c[i]].begin(),ind[c[i]].end(),i)-ind[c[i]].begin();
		kk.insert({ind[c[i]][jj],i+k});
		prev2[c[i]]=i+k;
	}

	for(int i=0;i<n+k;i++){
		WriteAdvice(ans[i]);
	}

 //	WriteAdvice(0);
}
/*int main(){
	int cc[4];
	cc[0]=2;
	cc[1]=0;
	cc[2]=3;
	cc[3]=0;

	ComputeAdvice(cc,4,2,1000);
	return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second

#include "assistant.h"
int arr[100001];
set<int> cur3;
set<int> cur4;
int ind3=0;
int rr;
//void PutBack(int x);
//int GetRequest();

/*int read(){
	int ans=0;

	for(int i=0;i<15;i++){
		if(aa[ind3+i]=='1'){
			ans+=(1<<i);
		}
	}
	ind3+=15;
	return ans;
}
int GetRequest(){
	int yy;
	cin>>yy;
	return yy;
}
void PutBack(int x){
	cout<<x<<":"<<endl;
}*/
void Assist(unsigned char aa[], int n, int k, int ro) {
/*	rr=ro;

	for(int i=0;i<ro;i++){
		aa[i]=A[i];
	}*/
	for(int i=0;i<k;i++){
		cur4.insert(i);
		if(aa[i]=='1'){
			cur3.insert(i);
		}
	//	cur3.insert(i);
	}
	int st=0;
	for (int i = 0; i < n; i++) {
		int req = GetRequest();
		if (cur4.find(req)==cur4.end()){
		 	PutBack((*cur3.begin()));
		 	cur4.erase((*cur3.begin()));
		 	cur3.erase(cur3.begin());
		 	if(aa[i+k]=='1'){
		 		cur3.insert(req);
		 	}
		 	cur4.insert(req);
		}
	}

}

/*int main(){
	int cc[4];
	int nn;
	cin>>nn;
	unsigned char aa[nn];
	for(int i=0;i<nn;i++){
		cin>>aa[i];
	}

	Assist(aa,4,2,nn);
	return 0;
}

*/

Compilation message

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:50:6: warning: unused variable 'st' [-Wunused-variable]
  int st=0;
      ^~
# Verdict Execution time Memory Grader output
1 Execution timed out 2600 ms 47616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2556 ms 49152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2565 ms 59920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2549 ms 48384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2504 ms 62352 KB Time limit exceeded
2 Execution timed out 2570 ms 62448 KB Time limit exceeded
3 Execution timed out 2525 ms 63216 KB Time limit exceeded
4 Execution timed out 2550 ms 63216 KB Time limit exceeded
5 Execution timed out 2526 ms 63208 KB Time limit exceeded
6 Execution timed out 2527 ms 63472 KB Time limit exceeded
7 Execution timed out 2525 ms 63216 KB Time limit exceeded
8 Execution timed out 2546 ms 63368 KB Time limit exceeded
9 Execution timed out 2513 ms 63216 KB Time limit exceeded
10 Execution timed out 2518 ms 63216 KB Time limit exceeded