#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;
vector<int> req[MAXN], away[MAXN];
bool has[MAXN];
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 away before x is requested again.
//best to away if it's not going to be requested again.
vector<int> ans;
for (int i = 0; i < N; i++) {
int x = C[i];
if (has[x]) {
ans.push_back(N); //awayove N - useless
} else {
int id = pq.top().se;
pq.pop();
away[id].push_back(i);
ans.push_back(id);
has[id] = false;
has[x] = true;
pq.push(pii(*upper_bound(all(req[x]), i), x));
}
}
for (int i = 0; i < N; i++) {
away[i].push_back(N);
}
//first - check if the last request is before it's first taken away
for (int i = 0; i < K; i++) {
WriteAdvice(req[i].front() > away[i].back()); //request only after you take it away for the last time
}
for (int i = 0; i < N; i++) {
//so take something out. and replace with new.
int nw = C[i];
WriteAdvice(*upper_bound(all(req[nw]), i) > away[nw].back());
}
}
#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 int cur[MAXN];
static bool has[MAXN];
static void go() {
priority_queue<pii> pq;
for (int i = 0; i < K; i++) {
cur[i] = i;
has[i] = true;
pq.emplace(A[i], i);
}
A += K;
for (int i = 0; i < N; i++) {
//replace it with this
int req = GetRequest();
if (has[req]) {
continue;
}
int ind = pq.top().se;
int &ref = cur[ind];
//debug("REF %d\n", ref);
PutBack(ref);
has[ref] = false;
pq.pop();
ref = req;
pq.emplace(A[i], ind);
has[req] = true;
}
}
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 |
9 ms |
9968 KB |
Output is correct |
2 |
Incorrect |
11 ms |
10040 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
11832 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
169 ms |
22744 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
22744 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
224 ms |
26008 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
226 ms |
26216 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
242 ms |
26216 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
204 ms |
26248 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
226 ms |
26248 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
186 ms |
26248 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
171 ms |
26248 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
188 ms |
26248 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
186 ms |
26248 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
219 ms |
26248 KB |
Output isn't correct - not an optimal way |