#include "advisor.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
void ComputeAdvice(int *c, int n, int k, int m) {
set <pii> K;
vector <int> in_K(n), in_N(n), used(n), met(n);
vector <vector <int>> pos(n);
for(int i = 0; i < n; i++){
if(c[i] < k && !used[c[i]]){
used[c[i]]++;
K.insert(mp(i, c[i]));
}
pos[c[i]].pb(i);
}
for(int i = 0; i < n; i++) pos[i].pb(n);
for(int i = 0; i < k; i++){
if(!used[i]) K.insert(mp(n, i));
}
for(int i = 0; i < n; i++){
used[i] = 0;
if(i < k) used[i] = 1;
}
vector <int> last(n, -1);
for(int i = 0; i < n; i++){
met[c[i]]++;
last[c[i]] = i;
if(!used[c[i]]){
auto to = (*K.rbegin());
K.erase(to);
if(!met[to.second]) in_K[to.second] = 1;
else in_N[last[to.second]] = 1;
used[to.second] = 0;
used[c[i]] = 1;
auto it = ub(all(pos[c[i]]), i);
K.insert(mp(*it, c[i]));
}
else{
auto it2 = K.find(mp(i, c[i]));
if(it2 != K.end()){
auto p = ub(all(pos[c[i]]), i);
K.erase(it2);
K.insert(mp(*p, c[i]));
}
}
}
for(int i = 0; i < k; i++){
WriteAdvice(in_K[i]);
}
for(int i = 0; i < n; i++){
WriteAdvice(in_N[i]);
}
}
/*
9 3 27
3 2 0 4 1 3 0 0 1
*/
#include "assistant.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
void Assist(unsigned char *a, int n, int k, int r) {
vector <int> v(n), used(n);
int ptr = 0;
for(int i = 0; i < k; i++) used[i] = 1;
for(int i = 0; i < n; i++){
int cur = GetRequest();
v[i] = cur;
if(used[cur] == 0){
while(ptr < r && !a[ptr]) ptr++;
if(ptr < k){
used[ptr] = 0;
PutBack(ptr);
}
else{
used[v[ptr-k]] = 0;
PutBack(v[ptr-k]);
}
ptr++;
used[cur] = 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
744 KB |
Output is correct |
3 |
Correct |
3 ms |
880 KB |
Output is correct |
4 |
Correct |
4 ms |
1240 KB |
Output is correct |
5 |
Correct |
6 ms |
1392 KB |
Output is correct |
6 |
Correct |
6 ms |
1184 KB |
Output is correct |
7 |
Correct |
6 ms |
1564 KB |
Output is correct |
8 |
Correct |
6 ms |
1564 KB |
Output is correct |
9 |
Correct |
6 ms |
1312 KB |
Output is correct |
10 |
Correct |
7 ms |
1396 KB |
Output is correct |
11 |
Correct |
7 ms |
1592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2012 KB |
Output is correct |
2 |
Correct |
61 ms |
6688 KB |
Output is correct |
3 |
Correct |
161 ms |
13712 KB |
Output is correct |
4 |
Correct |
104 ms |
11976 KB |
Output is correct |
5 |
Correct |
119 ms |
12148 KB |
Output is correct |
6 |
Correct |
131 ms |
12324 KB |
Output is correct |
7 |
Correct |
161 ms |
13496 KB |
Output is correct |
8 |
Correct |
112 ms |
11432 KB |
Output is correct |
9 |
Correct |
87 ms |
12384 KB |
Output is correct |
10 |
Correct |
160 ms |
13576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
10724 KB |
Output is correct |
2 |
Correct |
150 ms |
13384 KB |
Output is correct |
3 |
Correct |
157 ms |
13420 KB |
Output is correct |
4 |
Correct |
162 ms |
13444 KB |
Output is correct |
5 |
Correct |
142 ms |
13032 KB |
Output is correct |
6 |
Correct |
149 ms |
13500 KB |
Output is correct |
7 |
Correct |
151 ms |
13276 KB |
Output is correct |
8 |
Correct |
138 ms |
13232 KB |
Output is correct |
9 |
Correct |
130 ms |
13692 KB |
Output is correct |
10 |
Correct |
147 ms |
13704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1176 KB |
Output is correct |
2 |
Correct |
6 ms |
1440 KB |
Output is correct |
3 |
Correct |
4 ms |
1184 KB |
Output is correct |
4 |
Correct |
5 ms |
1312 KB |
Output is correct |
5 |
Correct |
5 ms |
1312 KB |
Output is correct |
6 |
Correct |
5 ms |
1184 KB |
Output is correct |
7 |
Correct |
7 ms |
1184 KB |
Output is correct |
8 |
Correct |
7 ms |
1568 KB |
Output is correct |
9 |
Correct |
7 ms |
1484 KB |
Output is correct |
10 |
Correct |
8 ms |
1812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
13148 KB |
Output is correct - 120000 bits used |
2 |
Correct |
153 ms |
13228 KB |
Output is correct - 122000 bits used |
3 |
Correct |
153 ms |
13436 KB |
Output is correct - 125000 bits used |
4 |
Correct |
155 ms |
13640 KB |
Output is correct - 125000 bits used |
5 |
Correct |
155 ms |
13316 KB |
Output is correct - 125000 bits used |
6 |
Correct |
154 ms |
13436 KB |
Output is correct - 125000 bits used |
7 |
Correct |
157 ms |
13588 KB |
Output is correct - 124828 bits used |
8 |
Correct |
160 ms |
13468 KB |
Output is correct - 124910 bits used |
9 |
Correct |
158 ms |
13316 KB |
Output is correct - 125000 bits used |
10 |
Correct |
143 ms |
13348 KB |
Output is correct - 125000 bits used |