#include "advisor.h"
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
namespace Advisor
{
const int MAXN = 1e5 + 5;
int maxLog;
int nxtSame[MAXN], firstSeen[MAXN];
vector <int> numSeq[MAXN];
void init(int n, int *a, int k)
{
for(int i = 0;i<k;i++)
{
for(int bit = 0;bit<=maxLog;bit++)
numSeq[i].push_back(((i>>bit)&1));
}
map <int, int> last;
for(int i = 0;i<n;i++)
{
last[i] = n;
firstSeen[i] = n;
}
for(int i = n-1;i>=0;i--)
{
nxtSame[i] = last[ a[i] ];
last[ a[i] ] = i;
firstSeen[ a[i] ] = i;
}
}
int calcLog(int x)
{
int ans = 0;
while(x!=1) x /= 2, ans++;
return ans;
}
template <class T>
T getLast(set <T> &s)
{
auto it = s.end();
it--;
return *it;
}
};
void ComputeAdvice(int *C, int N, int K, int M)
{
using namespace Advisor;
maxLog = calcLog(K);
init(N, C, K);
set <pair <int, int>> s;
vector <int> colorPos(N), scaffold(K);
vector <int> activated(N, -1);
for(int i = 0;i<N;i++)
{
colorPos[i] = -1;
}
for(int i = 0;i<K;i++)
{
scaffold[i] = i;
colorPos[i] = i;
s.insert({firstSeen[i], i});
}
vector <int> outScaffold(K, 0), outArr(N, 0);
for(int i = 0;i<N;i++)
{
//cout << " --- " << i << " --- " << '\n';
if(colorPos[ C[i] ]!=-1)
{
if(activated[ C[i] ]==-1) outScaffold[ C[i] ] = 1;
else outArr[ activated[ C[i] ] ] = 1;
activated[ C[i] ] = i;
s.erase({i, colorPos[ C[i] ]});
s.insert({nxtSame[i], colorPos[ C[i] ]});
continue;
}
//for(pair <int, int> item: s) cout << item.first << " " << item.second << " || ";
//cout << '\n';
pair <int, int> best = getLast(s);
s.erase(best);
//cout << best.first << " " << best.second << " -> " << scaffold[ best.second ] << '\n';
colorPos[ scaffold[best.second] ] = -1;
scaffold[best.second] = C[i];
colorPos[ C[i] ] = best.second;
//for(int bit: numSeq[best.second]) WriteAdvice(bit);
s.insert({nxtSame[i], best.second});
activated[ C[i] ] = i;
}
//for(int x: outScaffold) cout << x << " ";
//cout << '\n';
//for(int x: outArr) cout << x << " ";
//cout << '\n';
for(int x: outScaffold) WriteAdvice(x);
for(int x: outArr) WriteAdvice(x);
}
#include "assistant.h"
#include <set>
#include <queue>
#include <vector>
#include <assert.h>
#include <iostream>
using namespace std;
namespace Assitant
{
const int MAXN = 1e5 + 5;
int maxLog;
int calcLog(int x)
{
int ans = 0;
while(x!=1) x /= 2, ans++;
return ans;
}
struct Reader
{
queue <int> q;
Reader(){}
Reader(int n, unsigned char *a)
{
for(int i = 0;i<n;i++)
this->q.push(int(a[i]));
}
int readInt(int log2)
{
int x = 0;
for(int bit = 0;bit<=log2;bit++)
{
int d = q.front();
q.pop();
x += (d<<bit);
}
return x;
}
};
};
void Assist(unsigned char *A, int N, int K, int R)
{
vector <int> scaffoldActive(K), arrActive(N);
for(int i = 0;i<K;i++) scaffoldActive[i] = A[i];
for(int i = 0;i<N;i++) arrActive[i] = A[i+K];
set <int> passive, scaffold;
for(int i = 0;i<K;i++)
{
scaffold.insert(i);
if(scaffoldActive[i]==0)
passive.insert(i);
}
for(int iter = 0;iter<N;iter++)
{
int col = GetRequest();
if(scaffold.count(col)==true)
{
if(arrActive[iter]==0) passive.insert(col);
continue;
}
//cout << "passive: ";
//for(int x: passive) cout << x << " ";
//cout << '\n';
assert(passive.empty()==false);
int toRemove = *passive.begin();
scaffold.erase(toRemove);
passive.erase(toRemove);
PutBack(toRemove);
scaffold.insert(col);
if(arrActive[iter]==0) passive.insert(col);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5376 KB |
Output is correct |
2 |
Correct |
2 ms |
5376 KB |
Output is correct |
3 |
Correct |
4 ms |
5632 KB |
Output is correct |
4 |
Correct |
6 ms |
5632 KB |
Output is correct |
5 |
Correct |
8 ms |
6016 KB |
Output is correct |
6 |
Correct |
9 ms |
6144 KB |
Output is correct |
7 |
Correct |
10 ms |
6144 KB |
Output is correct |
8 |
Correct |
11 ms |
6144 KB |
Output is correct |
9 |
Correct |
11 ms |
6144 KB |
Output is correct |
10 |
Correct |
12 ms |
6400 KB |
Output is correct |
11 |
Correct |
11 ms |
6144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
6912 KB |
Output is correct |
2 |
Correct |
98 ms |
12544 KB |
Output is correct |
3 |
Correct |
267 ms |
23800 KB |
Output is correct |
4 |
Correct |
180 ms |
18416 KB |
Output is correct |
5 |
Correct |
189 ms |
18416 KB |
Output is correct |
6 |
Correct |
216 ms |
19440 KB |
Output is correct |
7 |
Correct |
243 ms |
21488 KB |
Output is correct |
8 |
Correct |
205 ms |
20208 KB |
Output is correct |
9 |
Correct |
160 ms |
18160 KB |
Output is correct |
10 |
Correct |
263 ms |
23024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
17904 KB |
Output is correct |
2 |
Correct |
250 ms |
22256 KB |
Output is correct |
3 |
Correct |
255 ms |
22256 KB |
Output is correct |
4 |
Correct |
249 ms |
22256 KB |
Output is correct |
5 |
Correct |
231 ms |
21488 KB |
Output is correct |
6 |
Correct |
255 ms |
22264 KB |
Output is correct |
7 |
Correct |
262 ms |
22256 KB |
Output is correct |
8 |
Correct |
234 ms |
22328 KB |
Output is correct |
9 |
Correct |
221 ms |
22512 KB |
Output is correct |
10 |
Correct |
247 ms |
22256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6144 KB |
Output is correct |
2 |
Correct |
11 ms |
6144 KB |
Output is correct |
3 |
Correct |
9 ms |
6144 KB |
Output is correct |
4 |
Correct |
9 ms |
6008 KB |
Output is correct |
5 |
Correct |
9 ms |
6144 KB |
Output is correct |
6 |
Correct |
10 ms |
6144 KB |
Output is correct |
7 |
Correct |
11 ms |
6144 KB |
Output is correct |
8 |
Correct |
12 ms |
6400 KB |
Output is correct |
9 |
Correct |
11 ms |
6144 KB |
Output is correct |
10 |
Correct |
13 ms |
6656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
20528 KB |
Output is correct - 120000 bits used |
2 |
Correct |
243 ms |
20720 KB |
Output is correct - 122000 bits used |
3 |
Correct |
260 ms |
21232 KB |
Output is correct - 125000 bits used |
4 |
Correct |
250 ms |
21376 KB |
Output is correct - 125000 bits used |
5 |
Correct |
272 ms |
21272 KB |
Output is correct - 125000 bits used |
6 |
Correct |
246 ms |
21488 KB |
Output is correct - 125000 bits used |
7 |
Correct |
255 ms |
21232 KB |
Output is correct - 124828 bits used |
8 |
Correct |
251 ms |
21232 KB |
Output is correct - 124910 bits used |
9 |
Correct |
256 ms |
21128 KB |
Output is correct - 125000 bits used |
10 |
Correct |
248 ms |
21240 KB |
Output is correct - 125000 bits used |