답안 #349778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349778 2021-01-18T11:47:55 Z amunduzbaev 최후의 만찬 (IOI12_supper) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#ifndef EVAL
#include "grader.cpp"
#endif
#include "advisor.h"
//#include "assistant.h"

using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>	
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
 
const int NN = 125005;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
int fir[NN];
vector<int> tmp[NN];
vector<int> used, last;
//int a[NN];

void Assist(unsigned char *a, int n, int k, int r) {
	//int last = 0;
	vector<int> A(n + k);
	used.assign(n, 0);
	set<int> ss;
	for(int i=0;i<k;i++) ss.insert(i), used[i] =1;
	for(int i=0;i<k;i++) A[i] = i;
	
	for(int l = 0, r = 0; r < n-k; r++){
		//for(auto x:ss) cout<<x<<" ";
		//cout<<"\n";
		//for(int i=0;i<r+k;i++) cout<<A[i]<<" ";
		//cout<<"\n";
		int cur = GetRequest();
		A[r + k] = cur;
		auto tt = ss.find(cur);
		if(tt != ss.end()) continue;
		while(l < r+k && !a[l]) l++;
		//cout<<A[l]<<"\n";
		PutBack(A[l]);
		
		ss.erase(A[l]);
		ss.insert(cur);
		l++;
	}
	
}

pii a[NN];
void ComputeAdvice(int *c, int n, int k, int m){
	used.assign(n, -1);
	for(int i=n-1;i>=0;i--){
		a[i] = {used[c[i]], c[i]};
		used[c[i]] = i;
		tmp[i] = used;
	}
	memset(fir, -1, sizeof fir);
	
	for(int i=0;i<n;i++){
		if(fir[c[i]] == -1) fir[c[i]] = i;
	}
	
	set<pii> ss;
	used.assign(n, 0);
	last.assign(n, -1);
	for(int i=0;i<k;i++) { last[i] = i, used[i] = 1; ss.insert({fir[i] == -1 ? mod : fir[i], i}); }
	
	vector<int> ans(n+k);
	for(int i=0;i<n;i++){
		//for(auto x:ss) cout<<x.ss<<" ";
		//cout<<"\n";
 		pii cur = a[i];
 		if(cur.ff == -1) cur.ff = mod;
 		if(used[cur.ss]){
			int tt = cur.ff;
			cur.ff = i;
			auto x = ss.lb(cur);
			if(x != ss.end()){
				ss.erase(x);
				ss.insert({tt, cur.ss});
			}
			last[cur.ss] = i+k;
			ans[i+k] = 0;
			continue;
		}
 		
		auto er = --ss.end();
		used[(*er).ss] = 0;
		used[cur.ss] = 1;
		//cout<<last[(*er).ss]<<" ";
		ans[last[(*er).ss]] = 1;
		last[cur.ss] = i+k;
		
		ss.erase(er);
		ss.insert(cur);
	}
	//cout<<"\n";
	
	//for(int i=0;i<n;i++) cout<<ans[i]<<" ";
	//cout<<"\n";
	for(int i=0;i<n;i++) WriteAdvice(ans[i]);
}

/*

9 3 1500000
4 3 1 5 2 4 1 1 2

12 3 1000
0 2 1 2 2 3 0 1 2 3 0 2

4 2 12
2 0 3 0

7 2 14
1 1 2 3 1 3 2

*/
#include <bits/stdc++.h>

#ifndef EVAL
#include "grader.cpp"
#endif
#include "advisor.h"
//#include "assistant.h"

using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>	
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
 
const int NN = 125005;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
int fir[NN];
vector<int> tmp[NN];
vector<int> used, last;
//int a[NN];

void Assist(unsigned char *a, int n, int k, int r) {
	//int last = 0;
	vector<int> A(n + k);
	used.assign(n, 0);
	set<int> ss;
	for(int i=0;i<k;i++) ss.insert(i), used[i] =1;
	for(int i=0;i<k;i++) A[i] = i;
	
	for(int l = 0, r = 0; r < n-k; r++){
		//for(auto x:ss) cout<<x<<" ";
		//cout<<"\n";
		//for(int i=0;i<r+k;i++) cout<<A[i]<<" ";
		//cout<<"\n";
		int cur = GetRequest();
		A[r + k] = cur;
		auto tt = ss.find(cur);
		if(tt != ss.end()) continue;
		while(l < r+k && !a[l]) l++;
		//cout<<A[l]<<"\n";
		PutBack(A[l]);
		
		ss.erase(A[l]);
		ss.insert(cur);
		l++;
	}
	
}

pii a[NN];
void ComputeAdvice(int *c, int n, int k, int m){
	used.assign(n, -1);
	for(int i=n-1;i>=0;i--){
		a[i] = {used[c[i]], c[i]};
		used[c[i]] = i;
		tmp[i] = used;
	}
	memset(fir, -1, sizeof fir);
	
	for(int i=0;i<n;i++){
		if(fir[c[i]] == -1) fir[c[i]] = i;
	}
	
	set<pii> ss;
	used.assign(n, 0);
	last.assign(n, -1);
	for(int i=0;i<k;i++) { last[i] = i, used[i] = 1; ss.insert({fir[i] == -1 ? mod : fir[i], i}); }
	
	vector<int> ans(n+k);
	for(int i=0;i<n;i++){
		//for(auto x:ss) cout<<x.ss<<" ";
		//cout<<"\n";
 		pii cur = a[i];
 		if(cur.ff == -1) cur.ff = mod;
 		if(used[cur.ss]){
			int tt = cur.ff;
			cur.ff = i;
			auto x = ss.lb(cur);
			if(x != ss.end()){
				ss.erase(x);
				ss.insert({tt, cur.ss});
			}
			last[cur.ss] = i+k;
			ans[i+k] = 0;
			continue;
		}
 		
		auto er = --ss.end();
		used[(*er).ss] = 0;
		used[cur.ss] = 1;
		//cout<<last[(*er).ss]<<" ";
		ans[last[(*er).ss]] = 1;
		last[cur.ss] = i+k;
		
		ss.erase(er);
		ss.insert(cur);
	}
	//cout<<"\n";
	
	//for(int i=0;i<n;i++) cout<<ans[i]<<" ";
	//cout<<"\n";
	for(int i=0;i<n;i++) WriteAdvice(ans[i]);
}

/*

9 3 1500000
4 3 1 5 2 4 1 1 2

12 3 1000
0 2 1 2 2 3 0 1 2 3 0 2

4 2 12
2 0 3 0

7 2 14
1 1 2 3 1 3 2

*/

Compilation message

advisor.cpp: In function 'void Assist(unsigned char*, int, int, int)':
advisor.cpp:55:13: error: 'GetRequest' was not declared in this scope
   55 |   int cur = GetRequest();
      |             ^~~~~~~~~~
advisor.cpp:61:3: error: 'PutBack' was not declared in this scope
   61 |   PutBack(A[l]);
      |   ^~~~~~~

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:55:13: error: 'GetRequest' was not declared in this scope
   55 |   int cur = GetRequest();
      |             ^~~~~~~~~~
assistant.cpp:61:3: error: 'PutBack' was not declared in this scope
   61 |   PutBack(A[l]);
      |   ^~~~~~~