#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(v.size() + 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++) sol[i] = false;
for (int i = 0; i < N; i++) las[i] = N + K;
for (int i = 0; i < v.size(); i++) {
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 {
//printf("inside %d\n", x); fflush(stdout);
sol[las[x]] = true;
s.erase({-q[x].front(), x});
q[x].pop();
s.insert({-q[x].front(), x});
}
las[x] = i;
}
for (auto iter : s) sol[las[iter.second]] = true;
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;
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)) {
assert(passive.size());
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++) sol[i] = false;
| ~~^~~~~~~~~~
advisor.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
advisor.cpp:31:8: warning: unused variable 'tr' [-Wunused-variable]
31 | int tr = s.begin()->second;
| ^~
advisor.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < v.size(); i++) WriteAdvice(sol[i]);
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
135092 KB |
Output is correct |
2 |
Correct |
68 ms |
135488 KB |
Output is correct |
3 |
Correct |
67 ms |
135668 KB |
Output is correct |
4 |
Correct |
64 ms |
135584 KB |
Output is correct |
5 |
Correct |
73 ms |
135268 KB |
Output is correct |
6 |
Correct |
74 ms |
135372 KB |
Output is correct |
7 |
Correct |
74 ms |
135484 KB |
Output is correct |
8 |
Correct |
78 ms |
135444 KB |
Output is correct |
9 |
Correct |
67 ms |
135500 KB |
Output is correct |
10 |
Correct |
73 ms |
135560 KB |
Output is correct |
11 |
Correct |
73 ms |
135516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
136040 KB |
Output is correct |
2 |
Correct |
110 ms |
138476 KB |
Output is correct |
3 |
Correct |
206 ms |
143492 KB |
Output is correct |
4 |
Correct |
130 ms |
140020 KB |
Output is correct |
5 |
Correct |
138 ms |
139936 KB |
Output is correct |
6 |
Correct |
165 ms |
140428 KB |
Output is correct |
7 |
Correct |
185 ms |
141828 KB |
Output is correct |
8 |
Correct |
199 ms |
141572 KB |
Output is correct |
9 |
Correct |
116 ms |
139884 KB |
Output is correct |
10 |
Correct |
197 ms |
142956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
140288 KB |
Output is correct |
2 |
Correct |
188 ms |
141468 KB |
Output is correct |
3 |
Correct |
194 ms |
141548 KB |
Output is correct |
4 |
Correct |
198 ms |
141520 KB |
Output is correct |
5 |
Correct |
197 ms |
140912 KB |
Output is correct |
6 |
Correct |
192 ms |
141528 KB |
Output is correct |
7 |
Correct |
203 ms |
141624 KB |
Output is correct |
8 |
Correct |
172 ms |
141564 KB |
Output is correct |
9 |
Correct |
175 ms |
142136 KB |
Output is correct |
10 |
Correct |
197 ms |
142524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
135468 KB |
Output is correct |
2 |
Correct |
68 ms |
135512 KB |
Output is correct |
3 |
Correct |
73 ms |
135268 KB |
Output is correct |
4 |
Correct |
91 ms |
135532 KB |
Output is correct |
5 |
Correct |
74 ms |
135452 KB |
Output is correct |
6 |
Correct |
74 ms |
135512 KB |
Output is correct |
7 |
Correct |
70 ms |
135512 KB |
Output is correct |
8 |
Correct |
76 ms |
135832 KB |
Output is correct |
9 |
Correct |
70 ms |
135568 KB |
Output is correct |
10 |
Correct |
77 ms |
135788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
140992 KB |
Output is correct - 120000 bits used |
2 |
Correct |
192 ms |
141208 KB |
Output is correct - 122000 bits used |
3 |
Correct |
206 ms |
141588 KB |
Output is correct - 125000 bits used |
4 |
Correct |
194 ms |
141476 KB |
Output is correct - 125000 bits used |
5 |
Correct |
192 ms |
141664 KB |
Output is correct - 125000 bits used |
6 |
Correct |
189 ms |
141560 KB |
Output is correct - 125000 bits used |
7 |
Correct |
198 ms |
141496 KB |
Output is correct - 124828 bits used |
8 |
Correct |
197 ms |
141504 KB |
Output is correct - 124910 bits used |
9 |
Correct |
193 ms |
141532 KB |
Output is correct - 125000 bits used |
10 |
Correct |
184 ms |
141704 KB |
Output is correct - 125000 bits used |