Submission #118495

# Submission time Handle Problem Language Result Execution time Memory
118495 2019-06-19T05:51:41 Z E869120 Last supper (IOI12_supper) C++14
100 / 100
133 ms 19544 KB
#include "advisor.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;

int E[100009], F[100009], A2[100009], A3[100009]; vector<int>X[100009];
priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>>Q;

void ComputeAdvice(int *C, int N, int K, int M) {
	int BITS = 0; for (int i = 0; i < 19; i++) { if ((1 << i) >= K) { BITS = i; break; } }

	for (int i = 0; i < N; i++) X[C[i]].push_back(i);
	for (int i = 0; i < N; i++) X[i].push_back(N);
	for (int i = 0; i < N; i++) E[i] = -1;
	for (int i = 0; i < K; i++) E[i] = i;
	for (int i = 0; i < N; i++) { Q.push(make_pair(X[i][0], i)); }

	for (int i = 0; i < N; i++) {
		while (true) {
			int pos1 = Q.top().first, pos2 = Q.top().second;
			if (E[pos2] == -1) Q.pop();
			else break;
		}
		if (E[C[i]] != -1) {
			F[i] = -1;
			int pos1 = lower_bound(X[C[i]].begin(), X[C[i]].end(), i) - X[C[i]].begin(); pos1--;
			if (pos1 >= 0) A2[X[C[i]][pos1]] = 1;
			else {
				A3[C[i]] = 1;
			}
		}
		else {
			int pos1 = Q.top().second;
			F[i] = E[pos1];
			E[pos1] = -1;
			E[C[i]] = F[i];
		}
		int pos1 = lower_bound(X[C[i]].begin(), X[C[i]].end(), i + 1) - X[C[i]].begin();
		Q.push(make_pair(X[C[i]][pos1], C[i]));
	}

	for (int i = 0; i < N; i++) WriteAdvice(A2[i]);
	for (int i = 0; i < K; i++) WriteAdvice(A3[i]);
}
#include "assistant.h"
#include <iostream>
#include <queue>
using namespace std;

int LIST[200009], B2[100009], B3[100009];
queue<int>Q; bool used[100009];

void Assist(unsigned char *A, int N, int K, int R) {
	for (int i = 0; i < N; i++) B2[i] = A[i];
	for (int i = 0; i < K; i++) B3[i] = A[i + N];
	for (int i = 0; i < K; i++) used[i] = true;
	for (int i = 0; i < K; i++) LIST[i + N] = i;

	for (int i = 0; i < K; i++) { if (B3[i] == 0) Q.push(i + N); }
	for (int i = 0; i < N; i++) {
		LIST[i] = GetRequest();
		if (used[LIST[i]] == true) {
			// 無視する
		}
		else {
			int pos = -1;
			while (!Q.empty()) {
				int pos1 = Q.front();
				if (used[LIST[pos1]] == true) { pos = pos1; break; }
				else Q.pop();
			}
			PutBack(LIST[pos]);
			used[LIST[pos]] = false;
			used[LIST[i]] = true;
			if (!Q.empty()) Q.pop();
		}
		if (B2[i] == 0) Q.push(i);
	}
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:23:8: warning: unused variable 'pos1' [-Wunused-variable]
    int pos1 = Q.top().first, pos2 = Q.top().second;
        ^~~~
advisor.cpp:13:6: warning: variable 'BITS' set but not used [-Wunused-but-set-variable]
  int BITS = 0; for (int i = 0; i < 19; i++) { if ((1 << i) >= K) { BITS = i; break; } }
      ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5376 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 5632 KB Output is correct
4 Correct 7 ms 5888 KB Output is correct
5 Correct 10 ms 6144 KB Output is correct
6 Correct 9 ms 6088 KB Output is correct
7 Correct 10 ms 6144 KB Output is correct
8 Correct 9 ms 6144 KB Output is correct
9 Correct 10 ms 6144 KB Output is correct
10 Correct 10 ms 6144 KB Output is correct
11 Correct 10 ms 6144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 6912 KB Output is correct
2 Correct 52 ms 12264 KB Output is correct
3 Correct 113 ms 18656 KB Output is correct
4 Correct 131 ms 18400 KB Output is correct
5 Correct 128 ms 18400 KB Output is correct
6 Correct 124 ms 18400 KB Output is correct
7 Correct 118 ms 18984 KB Output is correct
8 Correct 108 ms 16600 KB Output is correct
9 Correct 93 ms 19248 KB Output is correct
10 Correct 119 ms 19544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 16344 KB Output is correct
2 Correct 125 ms 19136 KB Output is correct
3 Correct 114 ms 19160 KB Output is correct
4 Correct 121 ms 19160 KB Output is correct
5 Correct 113 ms 19280 KB Output is correct
6 Correct 125 ms 19416 KB Output is correct
7 Correct 120 ms 19160 KB Output is correct
8 Correct 114 ms 18400 KB Output is correct
9 Correct 108 ms 19424 KB Output is correct
10 Correct 123 ms 19160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5888 KB Output is correct
2 Correct 9 ms 6144 KB Output is correct
3 Correct 10 ms 6400 KB Output is correct
4 Correct 10 ms 6400 KB Output is correct
5 Correct 10 ms 6144 KB Output is correct
6 Correct 10 ms 6144 KB Output is correct
7 Correct 10 ms 6400 KB Output is correct
8 Correct 10 ms 6400 KB Output is correct
9 Correct 10 ms 6144 KB Output is correct
10 Correct 10 ms 6400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 18952 KB Output is correct - 120000 bits used
2 Correct 114 ms 18912 KB Output is correct - 122000 bits used
3 Correct 122 ms 19168 KB Output is correct - 125000 bits used
4 Correct 114 ms 19160 KB Output is correct - 125000 bits used
5 Correct 110 ms 19080 KB Output is correct - 125000 bits used
6 Correct 124 ms 19472 KB Output is correct - 125000 bits used
7 Correct 122 ms 19424 KB Output is correct - 124828 bits used
8 Correct 126 ms 19360 KB Output is correct - 124910 bits used
9 Correct 119 ms 19160 KB Output is correct - 125000 bits used
10 Correct 133 ms 18392 KB Output is correct - 125000 bits used