#include "advisor.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M){
auto get=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
vector<int>v,on(N,0),cur(N,0);
K=min(K,N);
vector<int>occ[N+1];
for(int i=0;i<N;i++,C++)v.pb(*C),occ[v.back()].pb(i);
for(int i=0;i<N;i++)occ[i].pb(N);
vector<int>have;
set<pii>pq;
for(int i=0;i<K;i++)pq.insert({occ[i][0],have.size()}),have.pb(i),on[i]=1;
int mx=get(K);
int cnt=0;
for(auto i:v){
if(on[i]){
auto it=pq.lb({occ[i][cur[i]],0});
int pos=(*it).s;
pq.erase(it);
while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
pq.insert({occ[i][cur[i]],pos});
cnt++;
continue;
}
if(pq.empty())continue;
int pos=(*prev(pq.end())).s;
pq.erase(prev(pq.end()));
on[have[pos]]=0;
for(int j=0;j<=mx;j++){
if(pos&(1<<j))WriteAdvice(1);
else WriteAdvice(0);
}
while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
pq.insert({occ[i][cur[i]],pos});
have[pos]=i;
on[i]=1;
cnt++;
}
}
#include "assistant.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
void Assist(unsigned char *A, int N, int K, int R){
vector<int>have;
K=min(K,N);
auto get2=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
vector<int>on(N,0),pos(N,0);
priority_queue<pii>pq;
for(int i=0;i<K;i++)have.pb(i),on[i]=1,pos[i]=i;
int mx=get2(K);
for(int i=0;i<N;i++){
int x=GetRequest();
if(on[x])continue;
int val=0;
for(int j=0;j<=mx;j++,A++)val+=((1<<j)*(*A));
PutBack(have[val]);
on[have[val]]=0;
have[val]=x;
on[x]=1;
}
}
/*
10 2 20000
4 5 5 3 5 8 3 5 2 2
*/
Compilation message
advisor.cpp:33:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
33 | #pragma GCC optimize ("03,unroll-lopps")
| ^
advisor.cpp:35:47: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
35 | void ComputeAdvice(int *C, int N, int K, int M){
| ^
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:36:21: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
36 | auto get=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
| ^
advisor.cpp:52:19: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
advisor.cpp:65:17: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
advisor.cpp: In lambda function:
advisor.cpp:36:66: warning: control reaches end of non-void function [-Wreturn-type]
36 | auto get=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
| ^
assistant.cpp:33:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
33 | #pragma GCC optimize ("03,unroll-lopps")
| ^
assistant.cpp:35:50: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
35 | void Assist(unsigned char *A, int N, int K, int R){
| ^
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:38:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | auto get2=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
| ^
assistant.cpp: In lambda function:
assistant.cpp:38:67: warning: control reaches end of non-void function [-Wreturn-type]
38 | auto get2=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
792 KB |
Output is correct |
2 |
Correct |
1 ms |
788 KB |
Output is correct |
3 |
Correct |
1 ms |
784 KB |
Output is correct |
4 |
Correct |
3 ms |
1088 KB |
Output is correct |
5 |
Correct |
3 ms |
1092 KB |
Output is correct |
6 |
Correct |
6 ms |
1400 KB |
Output is correct |
7 |
Correct |
3 ms |
1340 KB |
Output is correct |
8 |
Correct |
7 ms |
1544 KB |
Output is correct |
9 |
Correct |
8 ms |
1428 KB |
Output is correct |
10 |
Correct |
6 ms |
1396 KB |
Output is correct |
11 |
Correct |
7 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2280 KB |
Output is correct |
2 |
Correct |
56 ms |
7572 KB |
Output is correct |
3 |
Correct |
157 ms |
17384 KB |
Output is correct |
4 |
Correct |
101 ms |
13484 KB |
Output is correct |
5 |
Correct |
137 ms |
15652 KB |
Output is correct |
6 |
Correct |
161 ms |
16240 KB |
Output is correct |
7 |
Correct |
142 ms |
16200 KB |
Output is correct |
8 |
Correct |
153 ms |
15488 KB |
Output is correct |
9 |
Correct |
80 ms |
12616 KB |
Output is correct |
10 |
Correct |
130 ms |
15712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
12920 KB |
Output is correct |
2 |
Correct |
147 ms |
15908 KB |
Output is correct |
3 |
Correct |
131 ms |
16004 KB |
Output is correct |
4 |
Correct |
130 ms |
15396 KB |
Output is correct |
5 |
Correct |
110 ms |
14128 KB |
Output is correct |
6 |
Correct |
137 ms |
15792 KB |
Output is correct |
7 |
Correct |
139 ms |
15660 KB |
Output is correct |
8 |
Correct |
170 ms |
18320 KB |
Output is correct |
9 |
Correct |
89 ms |
14120 KB |
Output is correct |
10 |
Correct |
135 ms |
15888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1056 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
16168 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
139 ms |
16112 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
132 ms |
15824 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
136 ms |
15748 KB |
Output is partially correct - 712005 bits used |
5 |
Correct |
133 ms |
15900 KB |
Output is partially correct - 710610 bits used |
6 |
Correct |
134 ms |
15724 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
136 ms |
15792 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
133 ms |
15840 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
142 ms |
15764 KB |
Output is partially correct - 712830 bits used |
10 |
Correct |
167 ms |
18392 KB |
Output is partially correct - 1117620 bits used |