#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 (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 |
6 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 |
12 ms |
6144 KB |
Output is correct |
6 |
Correct |
12 ms |
6200 KB |
Output is correct |
7 |
Correct |
10 ms |
6400 KB |
Output is correct |
8 |
Correct |
11 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 |
11 ms |
6144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
7168 KB |
Output is correct |
2 |
Correct |
64 ms |
13288 KB |
Output is correct |
3 |
Correct |
132 ms |
20344 KB |
Output is correct |
4 |
Correct |
141 ms |
19936 KB |
Output is correct |
5 |
Correct |
145 ms |
19936 KB |
Output is correct |
6 |
Correct |
133 ms |
20184 KB |
Output is correct |
7 |
Correct |
139 ms |
20448 KB |
Output is correct |
8 |
Correct |
117 ms |
17880 KB |
Output is correct |
9 |
Correct |
113 ms |
20696 KB |
Output is correct |
10 |
Correct |
139 ms |
20920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
17880 KB |
Output is correct |
2 |
Correct |
133 ms |
20704 KB |
Output is correct |
3 |
Correct |
149 ms |
20704 KB |
Output is correct |
4 |
Correct |
158 ms |
20952 KB |
Output is correct |
5 |
Correct |
123 ms |
20704 KB |
Output is correct |
6 |
Correct |
137 ms |
20696 KB |
Output is correct |
7 |
Correct |
148 ms |
20696 KB |
Output is correct |
8 |
Correct |
140 ms |
19912 KB |
Output is correct |
9 |
Correct |
130 ms |
20960 KB |
Output is correct |
10 |
Correct |
140 ms |
20704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6400 KB |
Output is correct |
2 |
Incorrect |
6 ms |
6144 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
147 ms |
20528 KB |
Output is partially correct - 220000 bits used |
2 |
Partially correct |
157 ms |
20800 KB |
Output is partially correct - 222000 bits used |
3 |
Partially correct |
156 ms |
20752 KB |
Output is partially correct - 225000 bits used |
4 |
Partially correct |
140 ms |
20696 KB |
Output is partially correct - 225000 bits used |
5 |
Partially correct |
144 ms |
20704 KB |
Output is partially correct - 225000 bits used |
6 |
Partially correct |
144 ms |
20704 KB |
Output is partially correct - 225000 bits used |
7 |
Partially correct |
142 ms |
20704 KB |
Output is partially correct - 224667 bits used |
8 |
Partially correct |
141 ms |
20960 KB |
Output is partially correct - 224910 bits used |
9 |
Partially correct |
134 ms |
20960 KB |
Output is partially correct - 225000 bits used |
10 |
Partially correct |
175 ms |
19760 KB |
Output is partially correct - 225000 bits used |