#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
void ComputeAdvice(int *a, int n, int k, int ___) {
vector<int> solution;
vector<int> when(n);
int tt = 0;
vector<vector<int>> nxt(n, vector<int> (1, n + 1));
for (int i = n - 1; i >= 0; i--) {
nxt[a[i]].push_back(i);
}
set<int> active_guys;
set<pair<int, int>> nxt_time;
for (int i = 0; i < k; i++) {
active_guys.insert(i);
nxt_time.insert({nxt[i].back(), i});
}
for (int i = 0; i < k; i++) {
when[i] = tt++;
solution.push_back(0);
}
int rr = 0;
for (int i = 0; i < n; i++) {
assert((int) nxt_time.size() == k);
if (!nxt_time.count({nxt[a[i]].back(), a[i]})) {
auto it = nxt_time.end(); it--;
int guy = it->second;
nxt_time.erase(it);
nxt_time.insert({nxt[a[i]].back(), a[i]});
rr++;
} else {
solution[when[a[i]]] = 1;
}
when[a[i]] = tt++;
solution.push_back(0);
nxt[a[i]].pop_back();
assert(nxt_time.count({i, a[i]}));
nxt_time.erase({i, a[i]});
nxt_time.insert({nxt[a[i]].back(), a[i]});
}
assert((int) nxt_time.size() == k);
for (auto &x : solution) {
WriteAdvice(x);
}
return;
for (auto &x : solution) {
cout << x << " ";
}
cout << "\n";
exit(0);
WriteAdvice(0);
WriteAdvice(1);
WriteAdvice(2);
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
void Assist(unsigned char *a, int n, int k, int r) {
set<int> act, skip;
int ptr = 0;
for (int i = 0; i < k; i++) {
act.insert(i);
if (a[ptr++] == 0) {
skip.insert(i);
}
}
//cout << "\t\t\tstart\n";
for (int i = 0; i < n; i++) {
int nxt = GetRequest();
if (!act.count(nxt)) {
assert(!skip.empty());
int x = *skip.begin();
//cout << "\t\t\t" << i << " : " << nxt << ", give " << x << " : " << int(a[ptr]) << " : " << (int) skip.size() << "\n";
skip.erase(x);
assert(act.count(x));
act.erase(x);
act.insert(nxt);
assert(ptr < r);
if (a[ptr++] == 0) {
skip.insert(nxt);
}
PutBack(x);
} else {
if (a[ptr++] == 0) {
skip.insert(nxt);
}
}
}
//exit(0);
return;
/**
int i;
set<int> give;
for (int i = )
for (i = 0; i < n; i++) {
int req = GetRequest();
if (req >= k)
PutBack(req % k);
}
**/
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:30:11: warning: unused variable 'guy' [-Wunused-variable]
30 | int guy = it->second;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
572 KB |
Output is correct |
2 |
Correct |
1 ms |
608 KB |
Output is correct |
3 |
Correct |
3 ms |
880 KB |
Output is correct |
4 |
Correct |
3 ms |
784 KB |
Output is correct |
5 |
Correct |
3 ms |
1048 KB |
Output is correct |
6 |
Correct |
5 ms |
1024 KB |
Output is correct |
7 |
Correct |
5 ms |
1196 KB |
Output is correct |
8 |
Correct |
6 ms |
1184 KB |
Output is correct |
9 |
Correct |
7 ms |
1176 KB |
Output is correct |
10 |
Correct |
7 ms |
1452 KB |
Output is correct |
11 |
Correct |
7 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1960 KB |
Output is correct |
2 |
Correct |
68 ms |
6220 KB |
Output is correct |
3 |
Correct |
191 ms |
17052 KB |
Output is correct |
4 |
Correct |
96 ms |
10068 KB |
Output is correct |
5 |
Correct |
124 ms |
10100 KB |
Output is correct |
6 |
Correct |
196 ms |
11160 KB |
Output is correct |
7 |
Correct |
177 ms |
13828 KB |
Output is correct |
8 |
Correct |
160 ms |
13404 KB |
Output is correct |
9 |
Correct |
82 ms |
10620 KB |
Output is correct |
10 |
Correct |
190 ms |
15892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
11252 KB |
Output is correct |
2 |
Correct |
208 ms |
14592 KB |
Output is correct |
3 |
Correct |
172 ms |
14888 KB |
Output is correct |
4 |
Correct |
218 ms |
14932 KB |
Output is correct |
5 |
Correct |
154 ms |
14128 KB |
Output is correct |
6 |
Correct |
182 ms |
14884 KB |
Output is correct |
7 |
Correct |
201 ms |
14916 KB |
Output is correct |
8 |
Correct |
170 ms |
14800 KB |
Output is correct |
9 |
Correct |
162 ms |
15372 KB |
Output is correct |
10 |
Correct |
175 ms |
14780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1152 KB |
Output is correct |
2 |
Correct |
8 ms |
1224 KB |
Output is correct |
3 |
Correct |
5 ms |
1064 KB |
Output is correct |
4 |
Correct |
5 ms |
1056 KB |
Output is correct |
5 |
Correct |
5 ms |
1032 KB |
Output is correct |
6 |
Correct |
6 ms |
1092 KB |
Output is correct |
7 |
Correct |
7 ms |
1192 KB |
Output is correct |
8 |
Correct |
7 ms |
1188 KB |
Output is correct |
9 |
Correct |
7 ms |
1320 KB |
Output is correct |
10 |
Correct |
8 ms |
1844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
167 ms |
13024 KB |
Output is correct - 120000 bits used |
2 |
Correct |
183 ms |
13440 KB |
Output is correct - 122000 bits used |
3 |
Correct |
216 ms |
13960 KB |
Output is correct - 125000 bits used |
4 |
Correct |
187 ms |
14044 KB |
Output is correct - 125000 bits used |
5 |
Correct |
182 ms |
13960 KB |
Output is correct - 125000 bits used |
6 |
Correct |
180 ms |
13960 KB |
Output is correct - 125000 bits used |
7 |
Correct |
194 ms |
13960 KB |
Output is correct - 124828 bits used |
8 |
Correct |
172 ms |
13924 KB |
Output is correct - 124910 bits used |
9 |
Correct |
179 ms |
14092 KB |
Output is correct - 125000 bits used |
10 |
Correct |
174 ms |
14016 KB |
Output is correct - 125000 bits used |