#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);
}
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]});
when[a[i]] = tt++;
solution.push_back(0);
} else {
solution[when[a[i]]] = 1;
}
nxt[a[i]].pop_back();
assert(nxt_time.count({i, a[i]}));
nxt_time.erase({i, a[i]});
nxt_time.insert({i, 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)) continue;
assert(!skip.empty());
int x = *skip.begin();
// cout << "\t\t\t" << i << " : " << nxt << ", give " << x << " : " << skip.count(1) << "\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);
}
//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:29:11: warning: unused variable 'guy' [-Wunused-variable]
29 | int guy = it->second;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Incorrect |
1 ms |
488 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
1848 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
10684 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1168 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
179 ms |
12672 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
153 ms |
12864 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
166 ms |
13384 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
164 ms |
13584 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
162 ms |
13448 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
165 ms |
13420 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
153 ms |
13364 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
158 ms |
13580 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
157 ms |
13480 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
188 ms |
13332 KB |
Output isn't correct - not an optimal way |