#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
void ComputeAdvice(int *c, int n, int k, int m){
vector<int> occ[n];
for(int i = n-1;i>=0;i--){
occ[c[i]].push_back(i);
}
for(int i = 0;i<k;i++){
WriteAdvice(occ[i].empty());
}
for(int i = 0;i<n;i++){
occ[c[i]].pop_back();
WriteAdvice(occ[c[i]].empty());
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
struct BIT{
vector<int> bit;
int n;
BIT(int size){
n = size+5;
bit.assign(n,0);
}
void upd(int pos,int val){
for(++pos;pos < n;pos += pos & -pos){
bit[pos] += val;
}
}
int get(int pos){
int ret = 0;
for(++pos;pos > 0;pos -= pos & -pos){
ret += bit[pos];
}
return ret;
}
int get(int l,int r){
return get(r) - get(l-1);
}
int get_kth(int k){
int pos = 0;
for(int i = 20;i>=0;i--){
if( pos + (1<<i) < n && bit[pos + (1<<i)] < k){
k -= bit[pos + (1<<i)];
pos += (1<<i);
}
}
return pos;
}
};
void Assist(unsigned char *a, int n, int k, int r) {
srand(time(NULL));
set<int> s,now;
BIT bt(n);
int last = 0;
for(int i = 0;i<k;i++){
if(a[last++] == 1){
s.insert(i);
}
now.insert(i);
bt.upd(i,1);
}
for (int i = 0; i < n; i++) {
int req = GetRequest();
if(now.count(req) == 0){
int num = bt.get_kth(rand()%k + 1);
if(s.size()){
num = *s.begin();
s.erase(s.begin());
}
now.erase(num);
bt.upd(num,-1);
PutBack(num);
now.insert(req);
bt.upd(req,1);
}
if(a[last++] == 1){
s.insert(req);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
740 KB |
Output is correct |
4 |
Incorrect |
3 ms |
676 KB |
Output isn't correct - not an optimal way |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1536 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
9132 KB |
Output is correct |
2 |
Correct |
152 ms |
11092 KB |
Output is correct |
3 |
Correct |
126 ms |
11232 KB |
Output is correct |
4 |
Correct |
137 ms |
10944 KB |
Output is correct |
5 |
Incorrect |
114 ms |
9884 KB |
Output isn't correct - not an optimal way |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
980 KB |
Output is correct |
2 |
Correct |
6 ms |
1076 KB |
Output is correct |
3 |
Incorrect |
6 ms |
948 KB |
Output isn't correct - not an optimal way |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
172 ms |
10568 KB |
Output isn't correct - not an optimal way |
2 |
Correct |
129 ms |
10748 KB |
Output is correct - 122000 bits used |
3 |
Correct |
148 ms |
11128 KB |
Output is correct - 125000 bits used |
4 |
Correct |
145 ms |
11032 KB |
Output is correct - 125000 bits used |
5 |
Correct |
124 ms |
11076 KB |
Output is correct - 125000 bits used |
6 |
Correct |
143 ms |
11068 KB |
Output is correct - 125000 bits used |
7 |
Correct |
124 ms |
11096 KB |
Output is correct - 124828 bits used |
8 |
Correct |
128 ms |
11208 KB |
Output is correct - 124910 bits used |
9 |
Correct |
126 ms |
11116 KB |
Output is correct - 125000 bits used |
10 |
Incorrect |
126 ms |
12140 KB |
Output isn't correct - not an optimal way |