QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442043 | #7942. $K$ Subsequences | HKOI0# | WA | 1ms | 5652kb | C++14 | 1.2kb | 2024-06-15 04:57:32 | 2024-06-15 04:57:33 |
Judging History
answer
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define int long long
using namespace std;
const int N = 2e5 + 11;
int a[N], b[N];
int n, k;
bool test(int x){
deque<int> dq; int bc = 0;
vector<int> rem;
for (int i = 1; i <= k; i++) {
rem.push_back(i);
}
for (int i = 0; i < n; i++) {
if (a[i] == -1) {
if (dq.empty()) {
b[i] = 1;
} else {
b[i] = dq.front();
rem.push_back(dq.front());
dq.pop_front();
if (dq.empty()) bc = 0;
}
} else {
if (x == 0) return false;
if (dq.empty() || bc == x) {
if (rem.empty()) return false;
b[i] = rem.back(); bc = 1;
rem.pop_back(); dq.push_back(b[i]);
} else {
b[i] = dq.back(); ++bc;
}
}
}
return true;
}
void solve(){
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int lo = 0, hi = n;
while (lo != hi) {
int mid = (lo + hi) / 2;
if (test(mid)) {
hi = mid;
} else {
lo = mid + 1;
}
}
test(lo);
for (int i = 0; i < n; i++) {
cout << b[i] << ' ';
}
cout << '\n';
}
int32_t main(){
#ifndef LOCAL
cin.tie(0)->sync_with_stdio(false);
#endif
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5652kb
input:
5 3 2 1 -1 1 4 2 -1 1 1 -1 7 3 1 1 1 1 1 1 1 10 3 1 1 1 1 -1 -1 1 1 1 1 12 4 1 1 1 1 -1 -1 -1 -1 1 1 1 1
output:
2 2 2 1 2 1 2 3 3 3 2 2 2 1 3 3 2 2 3 2 2 2 3 3 4 3 2 1 4 3 2 1 1 2 3 4
result:
wrong answer Jury found better answer than participant (test case 4)