Submission #926851

#TimeUsernameProblemLanguageResultExecution timeMemory
926851daoquanglinh2007Last supper (IOI12_supper)C++17
0 / 100
50 ms7680 KiB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair

const int NM = 2e5, inf = 1e9+7;

namespace advisor{
	int col[NM+5], lst[NM+5], nxt[NM+5];
	bool ok[NM+5];
	priority_queue <pii> q;
	bool ans[NM+5];
	void solve(int *C, int N, int K, int M){
		assert(M > 0);
		for (int i = 0; i < K; i++) col[i] = i;
		for (int i = 0; i < N; i++) col[K+i] = C[i];
		for (int i = 0; i < N; i++) lst[i] = -1;
		for (int i = N+K-1; i >= 0; i--){
			if (lst[col[i]] == -1) nxt[i] = +inf;
			else nxt[i] = lst[col[i]];
			lst[col[i]] = i;
		}
		for (int i = 0; i < K; i++) q.push(mp(+inf+1, -1));
		for (int i = 0; i < N+K; i++){
			if (ok[col[i]]) continue;
			pii P = q.top(); q.pop();
			if (P.se != -1){
				ans[P.se] = 1;
				ok[col[P.se]] = 0;
			}
			q.push(mp(nxt[i], i));
			ok[col[i]] = 1;
		}
		for (int i = 0; i < N+K; i++) WriteAdvice(ans[i]);
	}
}

void ComputeAdvice(int *C, int N, int K, int M){
	advisor::solve(C, N, K, M);
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair

const int NM = 2e5, inf = 1e9+7;

namespace assistant{
	queue <int> q;
	bool ok[NM+5];
	void solve(unsigned char *A, int N, int K, int R){
		assert(R == N+K);
		for (int i = 0; i < K; i++){
			ok[i] = 1;
			if (A[i]) q.push(i);
		}
		for (int i = 0; i < N; i++){
			int x = GetRequest();
			if (!ok[x]){
				int y = q.front(); q.pop();
				PutBack(y);
				ok[y] = 0;
				ok[x] = 1;
			}
			if (A[K+i]) q.push(x);
		}
	}
}

void Assist(unsigned char *A, int N, int K, int R){
	assistant::solve(A, N, K, R);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...