#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
int post[1 << 18], I[1 << 18]; vector<int> Z[1 << 18];
bool used[1 << 18];
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i = 0; i < N; i++) Z[C[i]].push_back(i);
for (int i = 0; i < N; i++) post[i] = (1 << 30);
for (int i = 0; i < N; i++) {
for (int j = (int)Z[i].size() - 2; j >= 0; j--) post[Z[i][j]] = Z[i][j + 1];
}
priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>> que;
for (int i = 0; i < K; i++) {
used[i] = true; I[i] = i;
if (Z[i].size() >= 1) que.push(make_pair(Z[i][0], i));
else que.push(make_pair((1 << 30), i));
}
//cout << "post = "; for (int i = 0; i < N; i++) cout << post[i] << ","; cout << endl;
vector<int> L;
for (int i = 0; i < N; i++) {
if (used[C[i]] == false) {
pair<int, int> G = que.top(); que.pop();
used[G.second] = false; I[C[i]] = I[G.second]; L.push_back(I[C[i]]);
}
que.push(make_pair(post[i], C[i])); used[C[i]] = true;
}
int sz = 1, size_ = 2;
while (size_ < K) { size_ *= 2; sz++; }
for (int i = 0; i < L.size(); i++) {
for (int j = 0; j < sz; j++) WriteAdvice((L[i] / (1 << j)) % 2);
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
int LL[1 << 18], DAI[1 << 18]; bool used2[1 << 18];
void Assist(unsigned char *A, int N, int K, int R) {
int sz = 1, size_ = 2;
while (size_ < K) { size_ *= 2; sz++; }
for (int i = 0; i < R / sz; i++) {
for (int j = 0; j < sz; j++) { LL[i] += A[i * sz + j] * (1 << j); }
}
for (int i = 0; i < K; i++) { used2[i] = true; DAI[i] = i; }
int cnt = 0;
for (int i = 0; i < N; i++) {
int G = GetRequest();
if (used2[G] == false) {
int nex = LL[cnt]; //cout << "request = " << G << ", nex = " << nex << ", initial value = " << DAI[nex] << ", num = " << LL[cnt] << endl;
PutBack(DAI[nex]); cnt++;
used2[G] = true; used2[DAI[nex]] = false; DAI[nex] = G;
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < L.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
13056 KB |
Output is correct |
2 |
Correct |
12 ms |
13056 KB |
Output is correct |
3 |
Correct |
13 ms |
13312 KB |
Output is correct |
4 |
Correct |
15 ms |
13312 KB |
Output is correct |
5 |
Correct |
13 ms |
13568 KB |
Output is correct |
6 |
Correct |
20 ms |
13824 KB |
Output is correct |
7 |
Correct |
16 ms |
13568 KB |
Output is correct |
8 |
Correct |
24 ms |
13824 KB |
Output is correct |
9 |
Correct |
20 ms |
13568 KB |
Output is correct |
10 |
Correct |
19 ms |
13824 KB |
Output is correct |
11 |
Correct |
13 ms |
13568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
14336 KB |
Output is correct |
2 |
Correct |
140 ms |
18424 KB |
Output is correct |
3 |
Correct |
369 ms |
29760 KB |
Output is correct |
4 |
Correct |
211 ms |
25568 KB |
Output is correct |
5 |
Correct |
250 ms |
27664 KB |
Output is correct |
6 |
Correct |
403 ms |
27744 KB |
Output is correct |
7 |
Correct |
251 ms |
27656 KB |
Output is correct |
8 |
Correct |
339 ms |
28168 KB |
Output is correct |
9 |
Correct |
164 ms |
22000 KB |
Output is correct |
10 |
Correct |
226 ms |
26464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
23912 KB |
Output is correct |
2 |
Correct |
303 ms |
26928 KB |
Output is correct |
3 |
Correct |
253 ms |
27152 KB |
Output is correct |
4 |
Correct |
291 ms |
26000 KB |
Output is correct |
5 |
Correct |
156 ms |
23664 KB |
Output is correct |
6 |
Correct |
261 ms |
26896 KB |
Output is correct |
7 |
Correct |
293 ms |
26856 KB |
Output is correct |
8 |
Correct |
322 ms |
31096 KB |
Output is correct |
9 |
Correct |
174 ms |
22056 KB |
Output is correct |
10 |
Correct |
258 ms |
27152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
13312 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
264 ms |
27440 KB |
Output is partially correct - 772365 bits used |
2 |
Partially correct |
292 ms |
26976 KB |
Output is partially correct - 742095 bits used |
3 |
Partially correct |
300 ms |
27312 KB |
Output is partially correct - 712470 bits used |
4 |
Partially correct |
297 ms |
26784 KB |
Output is partially correct - 712005 bits used |
5 |
Partially correct |
209 ms |
26896 KB |
Output is partially correct - 710610 bits used |
6 |
Partially correct |
250 ms |
26896 KB |
Output is partially correct - 712155 bits used |
7 |
Partially correct |
252 ms |
26896 KB |
Output is partially correct - 711090 bits used |
8 |
Partially correct |
228 ms |
26960 KB |
Output is partially correct - 713340 bits used |
9 |
Partially correct |
311 ms |
27152 KB |
Output is partially correct - 712830 bits used |
10 |
Partially correct |
333 ms |
30848 KB |
Output is partially correct - 1117620 bits used |