#include "advisor.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
int E[100009], F[100009], A1[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) {
A1[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 {
A1[i] = 0; // 前に線が無い
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(A1[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], B1[100009], 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++) B1[i] = A[i];
for (int i = 0; i < N; i++) B2[i] = A[i + N];
for (int i = 0; i < K; i++) B3[i] = A[i + N + 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 (B1[i] == 1) {
// 無視する
}
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 |
5 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 |
9 ms |
5888 KB |
Output is correct |
5 |
Correct |
11 ms |
6144 KB |
Output is correct |
6 |
Correct |
12 ms |
6144 KB |
Output is correct |
7 |
Correct |
9 ms |
6144 KB |
Output is correct |
8 |
Correct |
10 ms |
6144 KB |
Output is correct |
9 |
Correct |
10 ms |
6144 KB |
Output is correct |
10 |
Correct |
10 ms |
6200 KB |
Output is correct |
11 |
Correct |
10 ms |
6144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
7168 KB |
Output is correct |
2 |
Correct |
61 ms |
13288 KB |
Output is correct |
3 |
Correct |
126 ms |
20192 KB |
Output is correct |
4 |
Correct |
126 ms |
19944 KB |
Output is correct |
5 |
Correct |
134 ms |
19680 KB |
Output is correct |
6 |
Correct |
137 ms |
19936 KB |
Output is correct |
7 |
Correct |
125 ms |
20448 KB |
Output is correct |
8 |
Correct |
100 ms |
17624 KB |
Output is correct |
9 |
Correct |
107 ms |
20696 KB |
Output is correct |
10 |
Correct |
130 ms |
20696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
17624 KB |
Output is correct |
2 |
Correct |
184 ms |
20504 KB |
Output is correct |
3 |
Correct |
137 ms |
20448 KB |
Output is correct |
4 |
Correct |
134 ms |
20568 KB |
Output is correct |
5 |
Correct |
134 ms |
20496 KB |
Output is correct |
6 |
Correct |
127 ms |
20440 KB |
Output is correct |
7 |
Correct |
133 ms |
20800 KB |
Output is correct |
8 |
Correct |
130 ms |
19680 KB |
Output is correct |
9 |
Correct |
112 ms |
20808 KB |
Output is correct |
10 |
Correct |
135 ms |
20704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6144 KB |
Output is correct |
2 |
Incorrect |
8 ms |
6144 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
125 ms |
20200 KB |
Output is partially correct - 220000 bits used |
2 |
Partially correct |
138 ms |
20504 KB |
Output is partially correct - 222000 bits used |
3 |
Partially correct |
124 ms |
20448 KB |
Output is partially correct - 225000 bits used |
4 |
Partially correct |
130 ms |
20384 KB |
Output is partially correct - 225000 bits used |
5 |
Partially correct |
130 ms |
20704 KB |
Output is partially correct - 225000 bits used |
6 |
Partially correct |
127 ms |
20456 KB |
Output is partially correct - 225000 bits used |
7 |
Partially correct |
136 ms |
20448 KB |
Output is partially correct - 224667 bits used |
8 |
Partially correct |
131 ms |
20448 KB |
Output is partially correct - 224910 bits used |
9 |
Partially correct |
128 ms |
20440 KB |
Output is partially correct - 225000 bits used |
10 |
Partially correct |
137 ms |
19680 KB |
Output is partially correct - 225000 bits used |