/*************************************
* author: marvinthang *
* created: 04.06.2023 19:41:31 *
*************************************/
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i--; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
// end of template
void ComputeAdvice(int *C, int N, int K, int M) {
vector <int> nxt(N), last(N, N), pos(N, -1);
REPD(i, N) {
nxt[i] = last[C[i]];
last[C[i]] = i;
}
set <pair <int, int>> s;
REP(i, K) {
s.insert(make_pair(-last[i], i));
last[i] = i;
pos[i] = i;
}
vector <int> put(N + K);
REP(i, N) {
if (pos[C[i]] != -1) s.erase(make_pair(-i, C[i]));
else {
int x = s.begin()->se;
pos[C[i]] = pos[x];
put[x] = true;
last[x] = i + K;
pos[x] = -1;
s.erase(s.begin());
}
s.insert(make_pair(-nxt[i], C[i]));
}
for (int x: put) WriteAdvice(x);
}
/*************************************
* author: marvinthang *
* created: 04.06.2023 20:07:48 *
*************************************/
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i--; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
// end of template
void Assist(unsigned char *A, int N, int K, int R) {
vector <int> pos(N, -1), col(K);
vector <int> put;
REP(i, K) {
col[i] = pos[i] = i;
if (A[i]) put.push_back(i);
}
int cur = 0;
REP(i, N) {
int x = GetRequest();
if (pos[x] != -1) {
if (A[i + K]) put.push_back(x);
continue;
}
assert(!put.empty());
int v = put.back(); put.pop_back();
PutBack(v);
v = pos[v];
pos[col[v]] = -1;
col[v] = x;
pos[x] = v;
if (A[i + K]) put.push_back(x);
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:53:9: warning: unused variable 'cur' [-Wunused-variable]
53 | int cur = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
520 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
1300 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
5232 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
912 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
6004 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Incorrect |
78 ms |
6120 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Incorrect |
80 ms |
6412 KB |
Error - Putting back a color that is not on the scaffold |
4 |
Incorrect |
90 ms |
6324 KB |
Error - Putting back a color that is not on the scaffold |
5 |
Incorrect |
92 ms |
6332 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Incorrect |
77 ms |
6432 KB |
Error - Putting back a color that is not on the scaffold |
7 |
Incorrect |
106 ms |
6520 KB |
Error - Putting back a color that is not on the scaffold |
8 |
Incorrect |
80 ms |
6452 KB |
Error - Putting back a color that is not on the scaffold |
9 |
Incorrect |
79 ms |
6364 KB |
Error - Putting back a color that is not on the scaffold |
10 |
Incorrect |
71 ms |
6472 KB |
Error - Putting back a color that is not on the scaffold |