#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;
}
long long sz = 1, size_ = 2;
while (size_ < 1LL * K * K * K * K) { size_ *= 2; sz++; }
for (int i = 0; i < L.size(); i += 4) {
long long S1 = 0, S2 = 1;
for (int j = 0; j < 4; j++) { if (i + j < L.size()) { S1 += 1LL * S2 * L[i]; S2 *= K; } }
for (int j = 0; j < sz; j++) WriteAdvice((S2 / (1LL << 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) {
long long sz = 1, size_ = 2;
while (size_ < 1LL * K * K * K * K) { size_ *= 2; sz++; }
for (int i = 0; i < R / sz; i++) {
long long suma = 0;
for (int j = 0; j < sz; j++) {
suma += A[i * sz + j] * (1LL << j);
}
LL[i * 4 + 0] = (suma / (1LL)) % K;
LL[i * 4 + 1] = (suma / (1LL * K)) % K;
LL[i * 4 + 2] = (suma / (1LL * K * K)) % K;
LL[i * 4 + 3] = (suma / (1LL * K * K * K)) % K;
}
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 += 4) {
~~^~~~~~~~~~
advisor.cpp:37:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < 4; j++) { if (i + j < L.size()) { S1 += 1LL * S2 * L[i]; S2 *= K; } }
~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
13056 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
14336 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
184 ms |
22768 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
13312 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
258 ms |
26088 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
287 ms |
25688 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
242 ms |
25616 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
309 ms |
25616 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
311 ms |
25616 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
261 ms |
25616 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
276 ms |
25920 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
222 ms |
25872 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
295 ms |
25624 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
367 ms |
29560 KB |
Output isn't correct - not an optimal way |