#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);
}
priority_queue<pii> pq; //pii(next request, id)
for (int i = 0; i < K; i++) {
pq.push(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
} else {
nback++;
int id = pq.top().se;
pq.pop();
rem[id].push_back(i);
lastrem[id] = i;
ans.push_back(id);
has[id] = false;
has[x] = true;
pq.push(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)
^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9976 KB |
Output is correct |
2 |
Incorrect |
10 ms |
10056 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
11936 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
194 ms |
23304 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
23304 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
245 ms |
26056 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
219 ms |
26056 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
185 ms |
26200 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
267 ms |
26272 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
262 ms |
26272 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
250 ms |
26320 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
191 ms |
26320 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
186 ms |
26320 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
224 ms |
26320 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
197 ms |
26320 KB |
Output is correct - 125000 bits used |