#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int MAXN = 1e5+1;
int n,k,m;
int last[MAXN], last1[MAXN], req[MAXN], rem[MAXN], remc[MAXN];
bool z[MAXN];
void ComputeAdvice(int *C, int N, int K, int M) {
n = N; k = K; m = M;
FOR(i,0,n) last[i] = INF;
FORR(i,n-1,-1) {
req[i] = last[C[i]];
last[C[i]] = i;
}
PQ<PII> pq;
FOR(i,0,k) {
z[i] = 1;
pq.push({last[i],i});
}
vector<char> v;
FOR(i,0,n) {
if (z[C[i]]) {
remc[i] = -1;
pq.push({req[i],C[i]});
}
else {
while (!pq.empty() && !z[pq.top().S]) pq.pop();
int s = pq.top().S;
pq.pop();
remc[i] = s;
z[s] = 0;
z[C[i]] = 1;
pq.push({req[i],C[i]});
}
}
FOR(i,0,n) last1[i] = INF;
FORR(i,n-1,-1) {
rem[i] = last1[C[i]];
if (remc[i] != -1) last1[remc[i]] = i;
}
FOR(i,0,k) {
if (last[i] < last1[remc[i]]) WriteAdvice(1);
else WriteAdvice(0);
}
FOR(i,0,n) {
if (req[i] < rem[i]) WriteAdvice(1);
else WriteAdvice(0);
}
// FOR(i,0,n) cout << req[i] << ' ';
// cout << ln;
// FOR(i,0,n) cout << remc[i] << ' ';
// cout << ln;
}
// int a[MAXN];
// signed main() {
// OPTM;
// cin >> n >> k;
// FOR(i,0,n) cin >> a[i];
// ComputeAdvice(a,n,k,1);
// }
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
void Assist(unsigned char *A, int N, int K, int R) {
const int MAXN = 1e5+1;
int n,k,r;
n = N; k = K; r = R;
int act[MAXN];
bool z[MAXN];
FOR(i,0,MAXN) {
act[i] = z[i] = 0;
}
US<int> pas;
FOR(i,0,k) {
act[i] = A[i];
if (!act[i]) pas.insert(i);
}
FOR(i,0,k) z[i] = 1;
FOR(i,k,r) {
int cur = GetRequest();
act[cur] = A[i];
if (z[cur]) continue;
int x = *pas.begin();
PutBack(x);
pas.erase(x);
z[x] = 0;
z[cur] = 1;
if (!act[cur]) pas.insert(cur);
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:32:9: warning: variable 'n' set but not used [-Wunused-but-set-variable]
32 | int n,k,r;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1028 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1036 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
2560 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
8544 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1328 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
9984 KB |
Execution killed with signal 11 |
2 |
Runtime error |
63 ms |
10024 KB |
Execution killed with signal 11 |
3 |
Runtime error |
55 ms |
10608 KB |
Execution killed with signal 11 |
4 |
Runtime error |
57 ms |
10460 KB |
Execution killed with signal 11 |
5 |
Runtime error |
62 ms |
10540 KB |
Execution killed with signal 11 |
6 |
Runtime error |
66 ms |
10532 KB |
Execution killed with signal 11 |
7 |
Runtime error |
55 ms |
10532 KB |
Execution killed with signal 11 |
8 |
Runtime error |
54 ms |
10624 KB |
Execution killed with signal 11 |
9 |
Runtime error |
54 ms |
10580 KB |
Execution killed with signal 11 |
10 |
Incorrect |
53 ms |
8336 KB |
Output isn't correct - not an optimal way |