#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, -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;
in[a[i]] = i;
q.erase({a[i],i});
q.insert({a[i], next[i]});
}
else{ //out
ii cur = *q.begin(); q.erase(q.begin());
bits[cur.y] = 0;
in.erase(cur.x);
q.insert({next[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) {
map<int, int> s;
set<int> fre;
loop(i,0,k) {
s[i] = i;
if (!A[i]) fre.insert(i);
}
//cout<<"HI"<<endl;
loop(i,k,n+k){
int v = GetRequest();
if (s.find(v)!=s.end()){
int ind = s[v];
s[v] = i;
if (A[i]==A[ind]) continue;
if (!A[i]) fre.insert(v);
else fre.erase(v);
}
else{
int back = *fre.begin();
PutBack(back);
s.erase(back);
fre.erase(fre.begin());
if (!A[i]) fre.insert(v);
s[v] = i;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
772 KB |
Output is correct |
2 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
7288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
41 ms |
8056 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
40 ms |
8584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
46 ms |
9212 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
50 ms |
9464 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
43 ms |
9208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
54 ms |
9208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
45 ms |
9232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
43 ms |
9208 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
46 ms |
9408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Incorrect |
178 ms |
11504 KB |
Output isn't correct - not an optimal way |