#include "advisor.h"
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
using namespace std;
const int maxn = 2e5+10;
bool sol[maxn];
vector< int > v;
queue< int > q[maxn];
int las[maxn];
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i = 0; i < K; i++) v.push_back(i);
for (int i = 0; i < N; i++) v.push_back(C[i]);
for (int i = 0; i < v.size(); i++) {
q[v[i]].push(i);
}
for (int i = 0; i < N; i++) q[i].push(N + 1);
set< pair<int, int> > s;
for (int i = 0; i < K; i++) s.insert({-q[i].front(), i});
for (int i = 0; i < v.size(); i++) {
//printf("debug: %d\n", v[i]); fflush(stdout);
int x = v[i];
if (!s.count({-q[x].front(), x})) {
int tr = s.begin()->second;
s.erase(s.begin());
q[x].pop();
s.insert({-q[x].front(), x});
} else {
sol[las[x]] = 1;
s.erase({-q[x].front(), x});
q[x].pop();
s.insert({-q[x].front(), x});
}
las[x] = i;
}
for (int i = 0; i < v.size(); i++) WriteAdvice(sol[i]);
}
#include <bits/stdc++.h>
#include "assistant.h"
#define X first
#define Y second
using namespace std;
const int maxn = 1e5+10;
queue< int > qs[maxn];
void Assist(unsigned char *A, int N, int K, int R) {
set< int > active, passive;
for (int i = 0; i < K; i++) {
if (A[i] == 1) active.insert(i);
else passive.insert(i);
}
//printf("good\n"); fflush(stdout);
for (int i = 0; i < N; i++) {
int c = GetRequest();
//printf("debug: %d\n", c); fflush(stdout);
//printf("sizes: %d %d\n", active.size(), passive.size()); fflush(stdout);
if (!active.count(c) && !passive.count(c)) {
PutBack(*passive.begin());
passive.erase(passive.begin());
}
active.erase(c);
passive.erase(c);
if (A[i + K] == 1) active.insert(c);
else passive.insert(c);
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
advisor.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
advisor.cpp:30:8: warning: unused variable 'tr' [-Wunused-variable]
30 | int tr = s.begin()->second;
| ^~
advisor.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < v.size(); i++) WriteAdvice(sol[i]);
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
101 ms |
202520 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
122 ms |
203164 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
208276 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
107 ms |
202836 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
243 ms |
209212 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
247 ms |
209404 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
259 ms |
209724 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
247 ms |
209712 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
255 ms |
209784 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
239 ms |
209708 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
236 ms |
209796 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
259 ms |
209684 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
246 ms |
209920 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
221 ms |
209744 KB |
Output isn't correct - not an optimal way |