QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#284882 | #7942. $K$ Subsequences | ucup-team093# | WA | 1ms | 3488kb | C++20 | 1.7kb | 2023-12-16 15:26:56 | 2023-12-16 15:26:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n), tmp(n), ans;
for(int i = 0; i < n; i ++)
cin >> a[i];
if(-1 == *max_element(a.begin(), a.end())) {
for(int i = 0; i < n; i ++)
cout << "1" << " \n"[i + 1 == n];
return;
}
int l = 0, r = n;
while(l + 1 < r) {
int mid = (l + r) / 2;
if([&n, &k, &a, &tmp](int len) {
vector<int> full, c(k + 1, len);
queue<int> q;
for(int i = 1; i <= k; i ++)
q.push(i);
for(int i = 0; i < n; i ++) {
if(a[i] == 1) {
if(q.empty()) return false;
tmp[i] = q.front();
if(--c[q.front()] == 0) {
full.push_back(q.front());
q.pop();
}
}else{
if(full.size()) {
q.push(full.back());
tmp[i] = full.back();
c[full.back()] = len;
full.pop_back();
}else{
tmp[i] = q.front();
c[q.front()] = len;
}
}
}
return true;
}(mid)) {
ans = tmp;
r = mid;
}
else l = mid;
}
for(int i = 0; i < n; i ++)
cout << ans[i] << " \n"[i + 1 == n];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T --)
solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3488kb
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:
1 1 2 1 1 2 2 1 1 1 2 2 2 3 1 1 2 2 2 1 3 3 2 2 1 2 3 4 4 3 2 1 4 3 2 1
result:
wrong answer Jury found better answer than participant (test case 4)