#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int last[maxn], nex[maxn];
bool mark[maxn], Good[2*maxn];
void ComputeAdvice(int *C, int N, int K, int M) {
set<pair<int,int>> S;
memset(last, 63, sizeof last);
for (int i = N-1; i >= 0; i--){
nex[i] = last[C[i]];
last[C[i]] = i;
}
for (int i = 0; i < K; i++){
S.insert({-last[i], -(i+1)});
mark[i] = 1;
}
for (int i = 0; i < N; i++){
if (mark[C[i]]){
auto it = S.lower_bound(make_pair(-i,-maxn));
int idx = (*it).second;
cout << idx << " -> " << 1 << endl;
if (idx < 0)
Good[-(idx+1)] = 1;
else
Good[idx+K] = 1;
S.erase(it);
S.insert({-nex[i], i});
}
else{
auto it = S.begin();
int idx = (*it).second;
cout << idx << " -> " << 0 << endl;
if (idx < 0){
Good[-(idx+1)] = 0;
mark[-(idx+1)] = 0;
}
else{
Good[idx+K] = 0;
mark[C[idx]] = 0;
}
S.erase(it);
mark[C[i]] = 1;
S.insert({-nex[i], i});
}
}
for (int i = 0; i < N+K; i++)
cout << (char)(Good[i]+'0');
cout << endl;
for (int i = 0; i < N+K; i++)
WriteAdvice((char)(Good[i]+'0'));
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
const int maxn = 1e5 + 10;
bool mark2[maxn];
int C[maxn];
void Assist(unsigned char *A, int N, int K, int R) {
set<int> Bad;
for (int i = 0; i < K; i++)
if (A[i] == '0')
Bad.insert(i);
for (int i = 0; i < N; i++) {
int req = GetRequest();
C[i] = req;
if (mark2[req]){
if (A[i+K] == '0')
Bad.insert(C[i]);
continue;
}
assert(!Bad.empty());
int idx = *Bad.begin();
PutBack(idx);
mark2[idx] = 0;
mark2[C[i]] = 1;
Bad.erase(Bad.begin());
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1536 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
2048 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
249 ms |
7664 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
2048 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
322 ms |
9200 KB |
Error - Invalid Access |
2 |
Incorrect |
319 ms |
9208 KB |
Error - Invalid Access |
3 |
Incorrect |
317 ms |
9456 KB |
Error - Invalid Access |
4 |
Incorrect |
314 ms |
9456 KB |
Error - Invalid Access |
5 |
Incorrect |
342 ms |
9456 KB |
Error - Invalid Access |
6 |
Incorrect |
324 ms |
9456 KB |
Error - Invalid Access |
7 |
Incorrect |
328 ms |
9456 KB |
Error - Invalid Access |
8 |
Incorrect |
314 ms |
9712 KB |
Error - Invalid Access |
9 |
Incorrect |
310 ms |
9712 KB |
Error - Invalid Access |
10 |
Incorrect |
306 ms |
9456 KB |
Error - Invalid Access |