#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
struct Val {
int i, val;
bool operator <(const Val& v) const {
return val < v.val;
}
};
const int N = 1e5 + 10, INF = 1e9;
bool on[N];
char ch[] = {'0', '1'};
deque<int> pos[N], v[2];
int n1, m1, k1, c[N], nbbits1;
void addId(int i, int val, int bits) {
if(bits == 0)
return;
addId(i, val/2, bits-1);
v[i].push_back(val % 2);
//cout << val % 2;
}
void compute(int id) {
set<Val> last;
vector<int> suppr;
for(int i = 0; i < n1; i++) {
on[i] = false;
pos[i].clear();
}
for(int i = 0; i < n1; i++)
pos[c[i]].push_back(i);
for(int i = 0; i < n1; i++)
pos[i].push_back(INF);
for(int i = 0; i < k1; i++) {
if(id == 1) {
if(pos[i].size() == 0)
v[id].push_back(1);
else
v[id].push_back(0);
}
on[i] = true;
last.insert({i, pos[i][0]});
}
for(int i = 0; i < n1; i++) {
if(!on[c[i]]) {
on[c[i]] = true;
auto it = last.end();
it--;
/*for(Val v : last)
cout << v.val << ' ';
cout << '\n';*/
/*if(id == 1) {
if(pos[c[i]][0] == INF) {
v[id].push_back(1);
//cout << 1 << ' ';
} else {
v[id].push_back(0);
//cout << 0 << ' ';
}
if(suppr.empty()) {
on[(*it).i] = false;
addId(id, (*it).i, nbbits1);
//cout << ' ' ;
last.erase(it);
}
} else {*/
on[(*it).i] = false;
addId(id, (*it).i, nbbits1);
//cout << "suppr " << (*it).i << ' ' << (*it).val << '\n';
//cout << ' ' ;
last.erase(it);
//}
pos[c[i]].pop_front();
last.insert({c[i], pos[c[i]][0]});
}
}
}
void ComputeAdvice(int *C, int n2, int k2, int m2) {
n1 = n2;
k1 = k2;
m1 = m2;
v[0].push_back(0);
v[1].push_back(1);
nbbits1 = (int)ceil(log2(n1));
//cout << "BITS " << nbbits1 << '\n';
for(int i = 0; i < n1; i++)
c[i] = C[i];
compute(0);
//cout << '\n';
//compute(1);
//if(v[0].size() < v[1].size()) {
//cout << "0\n\n";
for(int i : v[0]) {
WriteAdvice(i);
}
/*} else {
//cout << "1\n\n";
for(int i : v[1]) {
WriteAdvice(i);
}
}*/
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, L = 2e6 + 10;
bool fin[L], in[N];
int n, k, len, nbbits, id = 1, b[L];
int read() {
int val = 0;
for(int i = 0; i < nbbits; i++) {
val = val * 2 + b[id];
//cout << b[id] << ' ';
id++;
}
/*cout << '\n';
cout << "READ " << val << '\n';*/
return val;
}
void traite() {
for(int i = 0; i < n; i++) {
int j = GetRequest();
if(!in[j]) {
in[j] = true;
int a = read();
in[a] = false;
//cout << a << '\n';
PutBack(a);
}
}
}
/*
void traiteSaute() {
vector<int> suppr;
for(int i = 0; i < k; i++) {
if(b[id] == 1) {
suppr.push_back(i);
}
id++;
}
for(int i = 0; i < n; i++) {
int j = GetRequest(),
t = b[id];
id++;
if(!in[j]) {
in[j] = true;
if(suppr.empty()) {
int a = read();
in[a] = false;
PutBack(a);
} else {
int a = suppr.back();
in[a] = false;
PutBack(suppr.back());
suppr.pop_back();
}
}
if(t == 1)
suppr.push_back(j);
}
}*/
void Assist(unsigned char *A, int n1, int k1, int r1) {
for(int i = 0; i < k1; i++)
in[i] = true;
/*for(int i = 0; i < r1; i++)
cout << (int)A[i];
cout << '\n';*/
n = n1;
k = k1;
len = r1;
for(int i = 0; i < len; i++)
if((A[i] == 1))
b[i] = 1;
else
b[i] = 0;
nbbits = (int)ceil(log2(n));
//cout << "BITS " << nbbits << '\n';
//if(A[0] == 0) {
traite();
/*} else {
traiteSaute();
}*/
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
67768 KB |
Output is correct |
2 |
Incorrect |
59 ms |
67748 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
104 ms |
69568 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
386 ms |
84800 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
68052 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
506 ms |
89776 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
452 ms |
89144 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
458 ms |
88440 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
435 ms |
88428 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
429 ms |
88464 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
478 ms |
88412 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
425 ms |
88356 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
419 ms |
88452 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
453 ms |
88452 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
466 ms |
89548 KB |
Output isn't correct - not an optimal way |