using namespace std;
#include <bits/stdc++.h>
#include "advisor.h"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<bool> vb;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
// void WriteAdvice(int x) {
// cout << x << " ";
// }
void ComputeAdvice(int *c, int n, int k, int m) {
bool debug = false;
int ans = 0;
set<int> scaffold;
rep(i,0,k) scaffold.insert(i);
vi advice(2*n, 0);
vi added(n, 0);
rep(i,0,k) added[i] = i;
vi nextOccurenceOfColor(n,1e9);
vi sweep(n,1e9);
for (int i = n - 1; i >= 0; i--) {
nextOccurenceOfColor[i] = sweep[c[i]];
sweep[c[i]] = i;
}
priority_queue<pair<int,int>> pq;
rep(i,0,k) pq.push({sweep[i], i});
if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
rep(i,0,n) {
int color = c[i];
added[color] = n+i;
pq.push({nextOccurenceOfColor[i], c[i]});
if (scaffold.find(color) != scaffold.end()) {
if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
continue;
}
pair<int,int> res = pq.top(); pq.pop();
if (debug) cout << "popped " << res.first << ", "<< res.second << endl;
int toRemove = res.second;
advice[added[toRemove]] = 1;
if (debug) cout << "advice at " << added[toRemove] << endl;
scaffold.erase(toRemove);
ans++;
scaffold.insert(c[i]);
if (debug) cout << "pushing " << c[i] << " with next occ " << nextOccurenceOfColor[i] << endl;
if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
}
rep(i,0,2*n) WriteAdvice(advice[i]);
if (debug) cout << "\nanswer: " << ans << endl;
}
// int main() {
// int c[] ={4, 1, 2, 1, 2, 1, 4, 2};
// ComputeAdvice(c, 8, 2, -1);
// }
using namespace std;
#include <bits/stdc++.h>
#include "assistant.h"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<bool> vb;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
void Assist(unsigned char *a, int n, int k, int r) {
set<int> scaffold;
rep(i,0,k) scaffold.insert(i);
vector<int> advice(2*n);
rep(i,0,2*n) advice[i] = a[i];
queue<int> q;
rep(i,0,k) if (advice[i] == 1) q.push(i);
rep(i,0,n) {
int nextColor = GetRequest();
if (scaffold.find(nextColor) == scaffold.end()) {
int rem = q.front(); q.pop();
PutBack(rem);
scaffold.erase(rem);
scaffold.insert(nextColor);
}
if (advice[n + i] == 1) {
q.push(nextColor);
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:40:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
40 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~
advisor.cpp:40:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
40 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~~~
advisor.cpp:48:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
48 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~
advisor.cpp:48:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
48 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~~~
advisor.cpp:63:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
63 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~
advisor.cpp:63:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
63 | if (debug) for (auto k : scaffold) cout << k << " "; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
520 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
1384 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
198 ms |
7688 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
932 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
255 ms |
9276 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Incorrect |
243 ms |
9528 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Incorrect |
231 ms |
9720 KB |
Error - Putting back a color that is not on the scaffold |
4 |
Incorrect |
256 ms |
9756 KB |
Error - Putting back a color that is not on the scaffold |
5 |
Incorrect |
297 ms |
9604 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Incorrect |
235 ms |
9788 KB |
Error - Putting back a color that is not on the scaffold |
7 |
Incorrect |
229 ms |
9612 KB |
Error - Putting back a color that is not on the scaffold |
8 |
Incorrect |
234 ms |
9724 KB |
Error - Putting back a color that is not on the scaffold |
9 |
Incorrect |
229 ms |
9776 KB |
Error - Putting back a color that is not on the scaffold |
10 |
Incorrect |
236 ms |
11868 KB |
Error - Putting back a color that is not on the scaffold |