#include "advisor.h"
#include <iostream>
#include <vector>
#include <set>
#include <cassert>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(xs) xs.begin(), xs.end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
#define MOD 1000000000
using namespace std;
typedef pair<int, int> P;
int OK[100000];
queue<int> G[100000];
inline int next(int c) {
if (G[c].empty()) return INF;
return G[c].front();
}
void ComputeAdvice(int *C, int N, int K, int M) {
rep(i, N) OK[i] = -1;
rep(i, N) G[C[i]].push(i);
priority_queue<P> pq;
rep(i, K) {
pq.push(P(next(i), i));
OK[i] = i;
}
vector<int> seq;
rep(i, N) {
int c = C[i];
G[c].pop();
pq.push(P(next(c), c));
if (OK[c] != -1) {
seq.pb(0);
}
else {
while (OK[pq.top()._2] == 1 || pq.top()._1 != next(pq.top()._2)) pq.pop();
int w = pq.top()._2;
int pos = OK[w];
OK[w] = -1;
pq.pop();
pq.push(P(next(c), c));
OK[c] = pos;
seq.pb(pos+1);
}
}
int per = 1, k = 1;
for (int k=0; k<20; k++) if (((K+1)>>k)&1) per = max(per, k+1);
//cout<<"{";for (int x : seq)cout<<x<<",";cout<<"}\n";
//cout<<"per="<<per<<"\n";
for (int x : seq) {
rep(i, per) {
WriteAdvice((x>>i)&1);
}
}
}
#include "assistant.h"
#include <iostream>
#include <vector>
#include <set>
#include <cassert>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(xs) xs.begin(), xs.end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
#define MOD 1000000000
using namespace std;
typedef pair<int, int> P;
int _OK[100000];
int slot[100000];
void Assist(unsigned char *A, int N, int K, int R) {
int per = 1, k = 1;
for (int k=0; k<20; k++) if (((K+1)>>k)&1) per = max(per, k+1);
vector<int> seq;
//cout<<"per="<<per<<"\n";
int head = 0;
rep(_, R/per) {
int s = 0;
rep(i, per) {
int bit = A[head++];
s |= bit<<i;
}
seq.pb(s);
}
//cout<<"{";for (int x : seq)cout<<x<<",";cout<<"}\n";
rep(i, N) _OK[i] = -1;
rep(i, K) _OK[i] = i, slot[i] = i;
rep(i, N) {
int c = GetRequest();
if (_OK[c] != -1) continue;
int back = slot[seq[i]-1];
PutBack(back);
_OK[back] = -1;
_OK[c] = back;
slot[seq[i]-1] = c;
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:54:16: warning: unused variable 'k' [-Wunused-variable]
int per = 1, k = 1;
^
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:23:16: warning: unused variable 'k' [-Wunused-variable]
int per = 1, k = 1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
135152 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
136848 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
401 ms |
145440 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
145440 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
454 ms |
148064 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
485 ms |
148064 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
445 ms |
148064 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
516 ms |
148064 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
425 ms |
148064 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
431 ms |
148064 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
427 ms |
148064 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
428 ms |
148064 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
455 ms |
148064 KB |
Output isn't correct - not an optimal way |
10 |
Partially correct |
445 ms |
148064 KB |
Output is partially correct - 1500000 bits used |