#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
static const int MAXN = 1e5 + 10;
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug(...)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#warning static (advisor)
static int *C, N, K, M;
static vector<int> req[MAXN], rem[MAXN];
static bool has[MAXN];
static int lastrem[MAXN];
static bool message (int nxtreq, int nxtrem) {
//request? or remove first?
//good if remove first or if both are N
return nxtreq > nxtrem;
}
void ComputeAdvice (int *ccc, int nnn, int kkk, int mmm) {
C = ccc;
N = nnn;
K = kkk;
M = mmm;
for (int i = 0; i < N; i++) {
req[C[i]].push_back(i);
}
for (int i = 0; i < N; i++) {
req[i].push_back(N);
}
set<pii> st; //pii(next request, id)
for (int i = 0; i < K; i++) {
st.insert(pii(req[i][0], i));
has[i] = true;
}
//there are 2 shelves
//one of them: x will be rem before x is requested again.
//best to rem if it's not going to be requested again.
//so the color is currently here
//there is some time where it will be requested again.
//Is it bound to have a removal before this?
for (int i = 0; i < N; i++) {
lastrem[i] = N;
}
int nback = 0;
vector<int> ans;
for (int i = 0; i < N; i++) {
int x = C[i];
if (has[x]) {
ans.push_back(N); //rem N - useless
assert(st.erase(pii(i, x)));
st.insert(pii(*upper_bound(all(req[x]), i), x));
} else {
nback++;
int id = (--st.end())->se;
st.erase(--st.end());
rem[id].push_back(i);
lastrem[id] = i;
ans.push_back(id);
has[id] = false;
has[x] = true;
st.insert(pii(*upper_bound(all(req[x]), i), x));
}
}
//debug("BACK SUPPOSED %d\n", nback);
for (int i = 0; i < N; i++) {
rem[i].push_back(N);
}
for (int i = 0; i < K; i++) {
bool msg = message(req[i].front(), rem[i].front());
WriteAdvice(msg);
}
for (int i = 0; i < N; i++) {
int col = C[i];
int nxtreq = *upper_bound(all(req[col]), i);
int nxtrem = *upper_bound(all(rem[col]), i);
//int nxtrem = *upper_bound(all(rem[col], i)); //NOT CORRECT!
//debug("PUT IN COLOR %d. nxtrem = %d, nxtreq = %d\n", col, nxtrem, nxtreq);
bool msg = message(nxtreq, nxtrem);
//debug("msg = %d\n", msg);
WriteAdvice(msg);
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
static const int MAXN = 1e5 + 10;
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug(...)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#warning static (assistant)
static unsigned char *A;
static int N, K;
static bool has[MAXN];
static bool stat[MAXN];
static set<pii> st;
void updstat (int x, bool s, bool chk) {
assert(st.erase(pii(stat[x], x)) == chk);
stat[x] = s;
st.insert(pii(stat[x], x));
}
static void go() {
for (int i = 0; i < K; i++) {
has[i] = true;
updstat(i, A[i], false);
}
A += K;
for (int i = 0; i < N; i++) {
//replace it with this
int req = GetRequest();
if (has[req]) {
//debug("HAS %d\n", req);
updstat(req, A[i], true);
} else {
int ind = (--st.end())->se;
PutBack(ind);
//debug("replace %d with %d\n", ref, req);
has[ind] = false;
has[req] = true;
//erase this one
st.erase(--st.end());
//ok now update this one
updstat(req, A[i], false);
}
}
}
void Assist (unsigned char *aaa, int nnn, int kkk, int rrr) {
A = aaa;
N = nnn;
K = kkk;
go();
}
Compilation message
advisor.cpp:17:2: warning: #warning static (advisor) [-Wcpp]
#warning static (advisor)
^~~~~~~
assistant.cpp:17:2: warning: #warning static (assistant) [-Wcpp]
#warning static (assistant)
^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9968 KB |
Output is correct |
2 |
Correct |
8 ms |
10200 KB |
Output is correct |
3 |
Correct |
9 ms |
10584 KB |
Output is correct |
4 |
Correct |
11 ms |
10856 KB |
Output is correct |
5 |
Correct |
14 ms |
11424 KB |
Output is correct |
6 |
Correct |
14 ms |
11584 KB |
Output is correct |
7 |
Correct |
16 ms |
11848 KB |
Output is correct |
8 |
Correct |
14 ms |
11896 KB |
Output is correct |
9 |
Correct |
15 ms |
12008 KB |
Output is correct |
10 |
Correct |
16 ms |
12056 KB |
Output is correct |
11 |
Correct |
16 ms |
12104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
12920 KB |
Output is correct |
2 |
Correct |
96 ms |
20096 KB |
Output is correct |
3 |
Correct |
319 ms |
31648 KB |
Output is correct |
4 |
Correct |
163 ms |
31648 KB |
Output is correct |
5 |
Correct |
174 ms |
31648 KB |
Output is correct |
6 |
Correct |
201 ms |
32280 KB |
Output is correct |
7 |
Correct |
242 ms |
34776 KB |
Output is correct |
8 |
Correct |
203 ms |
34776 KB |
Output is correct |
9 |
Correct |
132 ms |
36776 KB |
Output is correct |
10 |
Correct |
310 ms |
39288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
39288 KB |
Output is correct |
2 |
Correct |
256 ms |
39952 KB |
Output is correct |
3 |
Correct |
250 ms |
41104 KB |
Output is correct |
4 |
Correct |
244 ms |
42040 KB |
Output is correct |
5 |
Correct |
321 ms |
43016 KB |
Output is correct |
6 |
Correct |
251 ms |
44632 KB |
Output is correct |
7 |
Correct |
258 ms |
45768 KB |
Output is correct |
8 |
Correct |
213 ms |
46656 KB |
Output is correct |
9 |
Correct |
307 ms |
48568 KB |
Output is correct |
10 |
Correct |
246 ms |
49056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
49056 KB |
Output is correct |
2 |
Correct |
14 ms |
49056 KB |
Output is correct |
3 |
Correct |
12 ms |
49056 KB |
Output is correct |
4 |
Correct |
15 ms |
49056 KB |
Output is correct |
5 |
Correct |
14 ms |
49056 KB |
Output is correct |
6 |
Correct |
16 ms |
49056 KB |
Output is correct |
7 |
Correct |
18 ms |
49056 KB |
Output is correct |
8 |
Correct |
15 ms |
49056 KB |
Output is correct |
9 |
Correct |
17 ms |
49056 KB |
Output is correct |
10 |
Correct |
18 ms |
49056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
49256 KB |
Output is correct - 120000 bits used |
2 |
Correct |
239 ms |
49256 KB |
Output is correct - 122000 bits used |
3 |
Correct |
243 ms |
49552 KB |
Output is correct - 125000 bits used |
4 |
Correct |
264 ms |
49704 KB |
Output is correct - 125000 bits used |
5 |
Correct |
263 ms |
49704 KB |
Output is correct - 125000 bits used |
6 |
Correct |
247 ms |
49704 KB |
Output is correct - 125000 bits used |
7 |
Correct |
247 ms |
49792 KB |
Output is correct - 124828 bits used |
8 |
Correct |
262 ms |
49792 KB |
Output is correct - 124910 bits used |
9 |
Correct |
258 ms |
49792 KB |
Output is correct - 125000 bits used |
10 |
Correct |
222 ms |
49792 KB |
Output is correct - 125000 bits used |