Submission #829946

# Submission time Handle Problem Language Result Execution time Memory
829946 2023-08-18T16:06:58 Z Blagoj Last supper (IOI12_supper) C++17
100 / 100
2088 ms 21240 KB
#include <bits/stdc++.h>
#include "advisor.h"

using namespace std;

void ComputeAdvice(int *C, int N, int K, int M) {
    queue<int> toDelete;
	unordered_map<int, int> cnt;
	set<int> s[N + 2];
	int Last[N + 2];
	for (int i = 0; i < N; i++) {
		cnt[C[i]]++;
		s[C[i]].insert(i);
	}
	for (int i = 0; i < K; i++) {
		Last[i] = i;
		if (!cnt[i]) toDelete.push(i);
	}
	vector<int> op(N + K);
	unordered_set<int> have;
	for (int i = 0; i < K; i++) {
		have.insert(i);
		if (!cnt[i]) op[i] = 1;
	}
	for (int i = 0; i < N; i++) {
		Last[C[i]] = i + K;
		if (have.count(C[i])) {
			cnt[C[i]]--;
			if (!cnt[C[i]]) {
				toDelete.push(C[i]);
				op[i + K] = 1;
			}
		}
		else {
			if (toDelete.size() == 0) {
				int last, position = -1;
				for (int x : have) {
					int temp = *s[x].lower_bound(i); 
					if (temp > position) {
						position = temp;
						last = x;
					}
				}
				toDelete.push(last);
				op[Last[last]] = 1;
			}
			int fr = toDelete.front();
			toDelete.pop();
			have.erase(fr);
			have.insert(C[i]);
			cnt[C[i]]--;
			if (!cnt[C[i]]) {
				toDelete.push(C[i]);
				op[i + K] = 1;
			}
		}
	}
	for (int i = 0; i < op.size(); i++) {
		WriteAdvice(op[i]);
	}
}
#include <bits/stdc++.h>
#include "assistant.h"

using namespace std;

void Assist(unsigned char *A, int N, int K, int R) {
    queue<int> toDelete;
	unordered_set<int> have;
	for (int i = 0; i < K; i++) {
		if (A[i] == 1) toDelete.push(i);
		have.insert(i);
	}
	for (int i = 0; i < N; i++) {
        int req = GetRequest();
		if (!have.count(req)) {
			PutBack(toDelete.front());
			have.erase(toDelete.front());
			toDelete.pop();
			have.insert(req);
		}
        if (A[i + K] == 1) {
			toDelete.push(req);
		}
	}
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < op.size(); i++) {
      |                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 1 ms 900 KB Output is correct
4 Correct 3 ms 908 KB Output is correct
5 Correct 4 ms 1336 KB Output is correct
6 Correct 4 ms 1308 KB Output is correct
7 Correct 4 ms 1340 KB Output is correct
8 Correct 4 ms 1588 KB Output is correct
9 Correct 8 ms 1436 KB Output is correct
10 Correct 5 ms 1592 KB Output is correct
11 Correct 4 ms 1596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2256 KB Output is correct
2 Correct 569 ms 7780 KB Output is correct
3 Correct 2088 ms 21240 KB Output is correct
4 Correct 83 ms 16420 KB Output is correct
5 Correct 165 ms 16348 KB Output is correct
6 Correct 1140 ms 17024 KB Output is correct
7 Correct 583 ms 18488 KB Output is correct
8 Correct 73 ms 17664 KB Output is correct
9 Correct 90 ms 14124 KB Output is correct
10 Correct 86 ms 19672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 14560 KB Output is correct
2 Correct 84 ms 18016 KB Output is correct
3 Correct 90 ms 18172 KB Output is correct
4 Correct 79 ms 18016 KB Output is correct
5 Correct 985 ms 16668 KB Output is correct
6 Correct 81 ms 18160 KB Output is correct
7 Correct 81 ms 18120 KB Output is correct
8 Correct 99 ms 19640 KB Output is correct
9 Correct 1420 ms 17292 KB Output is correct
10 Correct 80 ms 19228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1308 KB Output is correct
2 Correct 4 ms 1564 KB Output is correct
3 Correct 4 ms 1180 KB Output is correct
4 Correct 4 ms 1336 KB Output is correct
5 Correct 4 ms 1352 KB Output is correct
6 Correct 4 ms 1336 KB Output is correct
7 Correct 5 ms 1468 KB Output is correct
8 Correct 4 ms 1472 KB Output is correct
9 Correct 4 ms 1456 KB Output is correct
10 Correct 5 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 17360 KB Output is correct - 120000 bits used
2 Correct 79 ms 17872 KB Output is correct - 122000 bits used
3 Correct 80 ms 18156 KB Output is correct - 125000 bits used
4 Correct 81 ms 18136 KB Output is correct - 125000 bits used
5 Correct 83 ms 18140 KB Output is correct - 125000 bits used
6 Correct 81 ms 18152 KB Output is correct - 125000 bits used
7 Correct 81 ms 18136 KB Output is correct - 124828 bits used
8 Correct 80 ms 18160 KB Output is correct - 124910 bits used
9 Correct 80 ms 18060 KB Output is correct - 125000 bits used
10 Correct 228 ms 19632 KB Output is correct - 125000 bits used