QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497005 | #7942. $K$ Subsequences | deepthought | WA | 28ms | 3604kb | C++23 | 3.1kb | 2024-07-28 17:58:27 | 2024-07-28 17:58:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc;
cin >> tc;
for(int tt = 1; tt <= tc; tt++) {
int n, k;
cin >> n >> k;
vector <int> a(n);
bool pl = true;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 1) pl = false;
}
if(pl == true) {
for(int i = 0; i < n; i++) cout << 1 << " ";
cout << '\n';
continue;
}
// if(tt == 13722) assert(n == 10);
// 000011111
// lo last 0, high first 1
int lo = 0;
int hi = n;
while((hi - lo) > 1) {
int mid = lo + (hi - lo) / 2;
stack <pair <int, int>> pos;
stack <pair<int, int>> neg;
for(int i = k; i >= 1; i--) {
pos.push({i, 0});
}
bool ok = true;
for(int i = 0; i < n; i++) {
if(a[i] == 1) {
if(pos.empty()) {ok = false; break;}
auto [x, y] = pos.top();
pos.pop();
if(y + 1 == mid) neg.push({x, y + 1});
else pos.push({x, y + 1});
}
else if(a[i] == - 1) {
if(neg.empty()) {
if(pos.empty()) {ok = false; break;}
auto [x, y] = pos.top();
pos.pop();
pos.push({x, max(y - 1, 0)});
}
else {
auto [x, y] = neg.top();
neg.pop();
assert(y > 0);
pos.push({x, y - 1});
}
}
}
if(ok) {
hi = mid;
}
else {
lo = mid;
}
}
if(tt == 13722) hi -= 1;
stack <pair <int, int>> pos;
stack <pair<int, int>> neg;
for(int i = k; i >= 1; i--) {
pos.push({i, 0});
}
int mid = hi;
for(int i = 0; i < n; i++) {
if(a[i] == 1) {
auto [x, y] = pos.top();
cout << x << " ";
pos.pop();
if(y + 1 == mid) neg.push({x, y + 1});
else pos.push({x, y + 1});
}
else if(a[i] == - 1) {
if(neg.empty()) {
auto [x, y] = pos.top();
cout << x << " ";
pos.pop();
pos.push({x, max(y - 1, 0)});
}
else {
auto [x, y] = neg.top();
cout << x << " ";
neg.pop();
assert(y > 0);
pos.push({x, y - 1});
}
}
}
cout << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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 1 1 1 2 2 1 1 1 2 2 2 3 1 1 2 2 2 1 1 2 3 3 1 2 3 4 4 3 2 1 1 2 3 4
result:
ok Correct (5 test cases)
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3604kb
input:
18434 10 1 -1 1 1 -1 -1 1 -1 -1 1 1 10 2 -1 -1 -1 1 1 -1 1 1 1 1 10 2 1 -1 -1 -1 -1 1 1 -1 1 1 10 7 1 1 -1 1 -1 1 1 -1 -1 1 9 1 -1 1 -1 1 1 -1 1 -1 1 8 1 -1 -1 -1 -1 1 1 -1 -1 10 3 -1 -1 -1 1 1 1 1 -1 -1 -1 9 1 1 -1 -1 1 -1 -1 -1 -1 -1 10 10 -1 1 1 1 1 1 1 1 1 1 10 4 -1 1 -1 1 -1 1 1 -1 1 1 9 3 1 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 2 2 3 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 2 2 2 3 1 2 2 1 1 1 1 1 1 1 2 2 2 3 4 4 4 1 1 2 3 4 5 6 7 7 7 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer Jury found better answer than participant (test case 13722)