#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) continue;
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);
}
int per = 1, k = 1;
for (int k=0; k<20; k++) if ((K>>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>>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);
}
reverse(all(seq));
//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.back()];
PutBack(back);
_OK[back] = -1;
_OK[c] = back;
slot[seq.back()] = c;
seq.pop_back();
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:50: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;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
135408 KB |
Output is correct |
2 |
Correct |
59 ms |
135680 KB |
Output is correct |
3 |
Correct |
61 ms |
135680 KB |
Output is correct |
4 |
Correct |
63 ms |
135848 KB |
Output is correct |
5 |
Correct |
67 ms |
135848 KB |
Output is correct |
6 |
Correct |
70 ms |
136024 KB |
Output is correct |
7 |
Correct |
65 ms |
136312 KB |
Output is correct |
8 |
Correct |
72 ms |
136312 KB |
Output is correct |
9 |
Correct |
71 ms |
136312 KB |
Output is correct |
10 |
Correct |
67 ms |
136312 KB |
Output is correct |
11 |
Correct |
69 ms |
136312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
136520 KB |
Output is correct |
2 |
Correct |
153 ms |
139248 KB |
Output is correct |
3 |
Correct |
348 ms |
145256 KB |
Output is correct |
4 |
Correct |
277 ms |
145256 KB |
Output is correct |
5 |
Correct |
344 ms |
145256 KB |
Output is correct |
6 |
Correct |
344 ms |
145256 KB |
Output is correct |
7 |
Correct |
315 ms |
145256 KB |
Output is correct |
8 |
Correct |
322 ms |
145256 KB |
Output is correct |
9 |
Correct |
208 ms |
145256 KB |
Output is correct |
10 |
Correct |
316 ms |
145256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
260 ms |
145256 KB |
Output is correct |
2 |
Correct |
356 ms |
145256 KB |
Output is correct |
3 |
Correct |
288 ms |
145256 KB |
Output is correct |
4 |
Correct |
273 ms |
145256 KB |
Output is correct |
5 |
Correct |
252 ms |
145256 KB |
Output is correct |
6 |
Correct |
291 ms |
145256 KB |
Output is correct |
7 |
Correct |
291 ms |
145256 KB |
Output is correct |
8 |
Correct |
402 ms |
145712 KB |
Output is correct |
9 |
Correct |
214 ms |
145712 KB |
Output is correct |
10 |
Correct |
287 ms |
145712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
145712 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
322 ms |
145712 KB |
Output is partially correct - 772365 bits used |
2 |
Partially correct |
292 ms |
145712 KB |
Output is partially correct - 742095 bits used |
3 |
Partially correct |
281 ms |
145712 KB |
Output is partially correct - 712470 bits used |
4 |
Partially correct |
290 ms |
145712 KB |
Output is partially correct - 712005 bits used |
5 |
Partially correct |
299 ms |
145712 KB |
Output is partially correct - 710610 bits used |
6 |
Partially correct |
333 ms |
145712 KB |
Output is partially correct - 712155 bits used |
7 |
Partially correct |
297 ms |
145712 KB |
Output is partially correct - 711090 bits used |
8 |
Partially correct |
292 ms |
145712 KB |
Output is partially correct - 713340 bits used |
9 |
Partially correct |
292 ms |
145712 KB |
Output is partially correct - 712830 bits used |
10 |
Partially correct |
377 ms |
145712 KB |
Output is partially correct - 1117620 bits used |