Submission #578976

# Submission time Handle Problem Language Result Execution time Memory
578976 2022-06-18T09:06:13 Z Justin1 Last supper (IOI12_supper) C++14
91 / 100
229 ms 96552 KB
#include <bits/stdc++.h>
#define f first
#define s second
#include "advisor.h"
using namespace std;

int endK[25005], endN[100005];
int endpos[100005];
deque<int> pos[100005];
set<int> pos2[100005];

string dectobin(int x, int mx) {
	string res = "";
	for (int i = mx; i >= 0; i--) {
		if ((1 << i) & x) res += '1';
		else res += '0';
	}
	return res;
}

void ComputeAdvice(int *C, int N, int K, int M) {
	if (M == 2'000'000) {
		int mx = log2(N-1);
		for (int i = 0; i < N; i++) {
			string tmp = dectobin(C[i],mx);
			for (auto j : tmp) WriteAdvice(j-'0');
		}
		return;
	}
	set<pair<int,int>> scaffold;
	for (int i = 0; i < K; i++) scaffold.insert({i,-1});
	for (int i = 0; i < N; i++) endN[i] = -1;
	for (int i = 0; i < N; i++) pos[C[i]].push_back(i);
	for (int i = 0; i < N; i++) pos[i].push_back(1e9);
	for (int i = 0; i < N; i++) {
		for (auto j : pos[i]) pos2[i].insert(j);
	}
	set<pair<int,int>> cur;
	for (int i = 0; i < K; i++) cur.insert({pos[i][0],i});
	for (int i = 0; i < N; i++) {
		string tmp;
		if (cur.find({pos[C[i]][0],C[i]}) != cur.end()) {
			cur.erase({pos[C[i]][0],C[i]});
			pos[C[i]].pop_front();
			cur.insert({pos[C[i]][0],C[i]});
		} else {
			pos[C[i]].pop_front();
			int tar = (*cur.rbegin()).s;
			auto tmp = *scaffold.lower_bound({tar,INT_MIN});
			if (tmp.s == -1) endK[tmp.f] = i;
			else endN[tmp.s] = i;
			scaffold.erase(scaffold.find(tmp));
			scaffold.insert({C[i],i});
			cur.erase(*cur.rbegin());
			cur.insert({pos[C[i]][0],C[i]});
		}
	}
	for (auto i : scaffold) {
		if (i.s == -1) endK[i.f] = 1e8;
		else endN[i.s] = 1e8;
	}
	for (int i = 0; i < K; i++) {
		endpos[i] = endK[i];
		int tmp = *pos2[i].lower_bound(0);
		WriteAdvice(tmp > endK[i]);
	}
	for (int i = 0; i < N; i++) {
		if (endN[i] == -1) {
			int tmp = *pos2[C[i]].upper_bound(i);
			WriteAdvice(tmp > endpos[C[i]]);
		} else {
			int tmp = *pos2[C[i]].upper_bound(i);
			WriteAdvice(tmp > endN[i]);
			endpos[C[i]] = endN[i];
		}
	}
}
#include <bits/stdc++.h>
#define f first
#define s second
#include "assistant.h"
using namespace std;
 
deque<int> put;
int col[100005];
int C[100005];
 
void Assist(unsigned char *A, int N, int K, int R) {
	if (R > 1'000'000) {
		deque<int> pos[100005];
		int lg = log2(N-1)+1;
		for (int i = 0; i < R; i++) {
			C[i/lg] += (1 << (lg - i % lg - 1)) * A[i];
		}
		for (int i = 0; i < N; i++) pos[C[i]].push_back(i);
		for (int i = 0; i < N; i++) pos[i].push_back(1e9);
		set<pair<int,int>> cur;
		for (int i = 0; i < K; i++) cur.insert({pos[i][0],i});
		for (int i = 0; i < N; i++) {
			GetRequest();
			if (cur.find({pos[C[i]][0],C[i]}) != cur.end()) {
				cur.erase({pos[C[i]][0],C[i]});
				pos[C[i]].pop_front();
				cur.insert({pos[C[i]][0],C[i]});
			} else {
				pos[C[i]].pop_front();
				PutBack((*cur.rbegin()).s);
				cur.erase(*cur.rbegin());
				cur.insert({pos[C[i]][0],C[i]});
			}
		}
		return;
	}
	for (int i = 0; i < K; i++) if (A[i]) put.push_back(i);
	for (int i = 0; i < K; i++) col[i] = 1;
	for (int i = K; i < R; i++) {
		int cur = GetRequest();
		if (col[cur]) {
			if (A[i]) put.push_back(cur);
			continue;
		}
		PutBack(put[0]);
		col[put[0]] = 0;
		col[cur] = 1;
		put.pop_front();
		if (A[i]) put.push_back(cur);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 80296 KB Output is correct
2 Correct 45 ms 80308 KB Output is correct
3 Correct 47 ms 80920 KB Output is correct
4 Correct 51 ms 80724 KB Output is correct
5 Correct 48 ms 81204 KB Output is correct
6 Correct 50 ms 81052 KB Output is correct
7 Correct 47 ms 81280 KB Output is correct
8 Correct 52 ms 81320 KB Output is correct
9 Correct 54 ms 81072 KB Output is correct
10 Correct 51 ms 81476 KB Output is correct
11 Correct 53 ms 81232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 81408 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 Correct 182 ms 93116 KB Output is correct
2 Correct 213 ms 96272 KB Output is correct
3 Correct 208 ms 96232 KB Output is correct
4 Correct 210 ms 96220 KB Output is correct
5 Correct 207 ms 95688 KB Output is correct
6 Correct 218 ms 96316 KB Output is correct
7 Correct 221 ms 96480 KB Output is correct
8 Correct 229 ms 96492 KB Output is correct
9 Correct 197 ms 96292 KB Output is correct
10 Correct 210 ms 96272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 80976 KB Output is correct
2 Correct 51 ms 81256 KB Output is correct
3 Correct 48 ms 81104 KB Output is correct
4 Correct 49 ms 81284 KB Output is correct
5 Correct 47 ms 81180 KB Output is correct
6 Correct 62 ms 81228 KB Output is correct
7 Correct 51 ms 81328 KB Output is correct
8 Correct 52 ms 81260 KB Output is correct
9 Correct 52 ms 81580 KB Output is correct
10 Correct 55 ms 81436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 95764 KB Output is correct - 120000 bits used
2 Correct 219 ms 96016 KB Output is correct - 122000 bits used
3 Correct 226 ms 96288 KB Output is correct - 125000 bits used
4 Correct 215 ms 96240 KB Output is correct - 125000 bits used
5 Correct 213 ms 96320 KB Output is correct - 125000 bits used
6 Correct 227 ms 96552 KB Output is correct - 125000 bits used
7 Correct 225 ms 96292 KB Output is correct - 124828 bits used
8 Correct 215 ms 96252 KB Output is correct - 124910 bits used
9 Correct 212 ms 96324 KB Output is correct - 125000 bits used
10 Correct 213 ms 96432 KB Output is correct - 125000 bits used