#include "advisor.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define vb vector<bool>
#define ii pair<int,int>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 1e9, MOD=1e9+7;
void ComputeAdvice(int *C, int n, int k, int M) {
vi a(n+k);
loop(i,0,k) a[i]=i;
loop(i,0,n) a[i+k]=C[i];
vi next(n+k);
vi last(n, n+k+1);
loopr(i,0,n+k) {
next[i] = last[a[i]];
last[a[i]] = i;
}
set<ii> q;
map<int, int> in;
loop(i,0,k) {
q.insert({next[i],i});
in[i] = i;
}
vb bits(n+k);
loop(i,k,n+k){
if (in.find(a[i])!=in.end()){ //already in
bits[in[a[i]]] = 1;
q.erase(q.lower_bound({i, -INF}));
}
else{ //out
ii cur = *q.rbegin(); q.erase(cur);
bits[cur.y] = 0;
in.erase(a[cur.y]);
}
q.insert({next[i], i});
in[a[i]] = i;
}
loop(i,0,n+k) WriteAdvice(bits[i]);
}
/*
color a
cls
g++ advisor.cpp -o a & a
*/
#include "assistant.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define vb vector<bool>
#define ii pair<int,int>
#define vvi vector<vi>
#define vvb vector<vb>
#define vii vector<ii>
#define vvii vector<vii>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
using namespace std;
const int INF = 1e9, MOD=1e9+7;
void Assist(unsigned char *A, int n, int k, int R) {
set<int> s;
set<int> fre;
loop(i,0,k) {
s.insert(i);
if (!A[i]) fre.insert(i);
}
//cout<<"HI"<<endl;
loop(i,k,n+k){
int v = GetRequest();
if (s.find(v)!=s.end()){
if (fre.find(v)!=fre.end()) fre.erase(v);
}
else{
int back = *fre.begin();
PutBack(back);
s.erase(back);
fre.erase(back);
}
s.insert(v);
if (!A[i]) fre.insert(v);
}
}
/*
color a
cls
g++ assistant.cpp -o a & a
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
644 KB |
Output is correct |
2 |
Correct |
1 ms |
772 KB |
Output is correct |
3 |
Correct |
2 ms |
908 KB |
Output is correct |
4 |
Correct |
4 ms |
920 KB |
Output is correct |
5 |
Correct |
5 ms |
1104 KB |
Output is correct |
6 |
Correct |
7 ms |
1024 KB |
Output is correct |
7 |
Correct |
8 ms |
1284 KB |
Output is correct |
8 |
Correct |
8 ms |
1120 KB |
Output is correct |
9 |
Correct |
9 ms |
1104 KB |
Output is correct |
10 |
Correct |
10 ms |
1408 KB |
Output is correct |
11 |
Correct |
9 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1516 KB |
Output is correct |
2 |
Correct |
89 ms |
3824 KB |
Output is correct |
3 |
Correct |
256 ms |
12272 KB |
Output is correct |
4 |
Correct |
118 ms |
5104 KB |
Output is correct |
5 |
Correct |
141 ms |
5428 KB |
Output is correct |
6 |
Correct |
184 ms |
6384 KB |
Output is correct |
7 |
Correct |
224 ms |
9200 KB |
Output is correct |
8 |
Correct |
191 ms |
9464 KB |
Output is correct |
9 |
Correct |
106 ms |
5104 KB |
Output is correct |
10 |
Correct |
252 ms |
11248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
7408 KB |
Output is correct |
2 |
Correct |
249 ms |
9208 KB |
Output is correct |
3 |
Correct |
234 ms |
9208 KB |
Output is correct |
4 |
Correct |
230 ms |
9200 KB |
Output is correct |
5 |
Correct |
236 ms |
8176 KB |
Output is correct |
6 |
Correct |
261 ms |
10224 KB |
Output is correct |
7 |
Correct |
239 ms |
10224 KB |
Output is correct |
8 |
Correct |
240 ms |
10224 KB |
Output is correct |
9 |
Correct |
208 ms |
10224 KB |
Output is correct |
10 |
Correct |
241 ms |
10224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1188 KB |
Output is correct |
2 |
Correct |
9 ms |
1064 KB |
Output is correct |
3 |
Correct |
7 ms |
952 KB |
Output is correct |
4 |
Correct |
6 ms |
1024 KB |
Output is correct |
5 |
Correct |
7 ms |
1104 KB |
Output is correct |
6 |
Correct |
7 ms |
1024 KB |
Output is correct |
7 |
Correct |
9 ms |
1268 KB |
Output is correct |
8 |
Correct |
12 ms |
1104 KB |
Output is correct |
9 |
Correct |
9 ms |
1408 KB |
Output is correct |
10 |
Correct |
12 ms |
1752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
8008 KB |
Output is correct - 120000 bits used |
2 |
Correct |
229 ms |
8432 KB |
Output is correct - 122000 bits used |
3 |
Correct |
233 ms |
9200 KB |
Output is correct - 125000 bits used |
4 |
Correct |
236 ms |
9200 KB |
Output is correct - 125000 bits used |
5 |
Correct |
237 ms |
9200 KB |
Output is correct - 125000 bits used |
6 |
Correct |
237 ms |
9200 KB |
Output is correct - 125000 bits used |
7 |
Correct |
234 ms |
9200 KB |
Output is correct - 124828 bits used |
8 |
Correct |
239 ms |
9200 KB |
Output is correct - 124910 bits used |
9 |
Correct |
263 ms |
9200 KB |
Output is correct - 125000 bits used |
10 |
Correct |
236 ms |
9200 KB |
Output is correct - 125000 bits used |