QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#497000 | #7942. $K$ Subsequences | deepthought | WA | 28ms | 3624kb | C++23 | 3.7kb | 2024-07-28 17:54:25 | 2024-07-28 17:54:26 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define err(x) cerr << "["#x"] " << (x) << "\n"
#define erra(x, n) { cerr << "["#x"] ["; for (size_t i = 0; i < (n); ++i) cerr << "{" << i << ": " << (x)[i] << "}, "; cerr << "]\n"; }
#define errv(x) { cerr << "["#x"] ["; for (size_t i = 0; i < (x).size(); ++i) cerr << "{" << i << ": " << (x)[i] << "}, "; cerr << "]\n"; }
#define errm(x) { cerr << "["#x"] ["; for (const auto& [k, v] : (x)) cerr << "{" << k << ": " << v << "}, "; cerr << "]\n"; }
#define MOD 1000000007
#define MAXX 2000005 // 1e6+5
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 < 15);
// 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;
}
}
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';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 3624kb
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 14722)