QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136142 | #5719. Perfect Flush | Nicolas125841 | WA | 17ms | 4652kb | C++17 | 1.7kb | 2023-08-07 12:34:24 | 2023-08-07 12:34:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int n, k, v;
cin >> n >> k;
vector<int> ar(n);
for(int i = 0; i < n; i++)
cin >> ar[i];
vector<bool> found(k + 1, false);
vector<bool> last(n, false);
for(int i = n - 1; i >= 0; i--){
if(!found[ar[i]]){
found[ar[i]] = true;
last[i] = true;
}
}
int lb = 1;
vector<bool> mex(k + 2, false);
vector<int> stack;
vector<int> result;
mex[0] = true;
for(int i = 0; i < n; i++){
if(mex[ar[i]])
continue;
if(lb == ar[i]){
stack.clear();
result.push_back(ar[i]);
mex[ar[i]] = true;
}else if(lb < ar[i]){
if(last[i]){
int m_size = result.size();
stack.push_back(ar[i]);
for(int j = 0; j < stack.size(); j++){
while(result.size() > m_size && result.back() >= stack[j]){
mex[result.back()] = false;
result.pop_back();
}
mex[stack[j]] = true;
result.push_back(stack[j]);
}
stack.clear();
}else{
stack.push_back(ar[i]);
}
}
while(mex[lb])
lb++;
}
vector<bool> hit(k+1, false);
assert(result.size() == k);
for(int i = 0; i < k; i++){
assert(!hit[result[i]]);
hit[result[i]] = true;
}
for(int &r : result)
cout << r << " ";
cout << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
input:
6 3 3 2 1 3 1 3
output:
2 1 3
result:
ok single line: '2 1 3 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
10 5 5 4 3 2 1 4 1 1 5 5
output:
3 2 1 4 5
result:
ok single line: '3 2 1 4 5 '
Test #3:
score: -100
Wrong Answer
time: 17ms
memory: 4652kb
input:
200000 100000 29798 79235 44935 20368 15319 34973 11273 40142 82579 68354 79772 77697 59566 18516 50787 76175 25710 47305 87751 59942 49064 26470 38196 44038 38745 39903 71503 18468 59632 23169 10201 26065 62767 44170 37027 69281 7161 62056 7829 13359 80329 68362 59458 6406 80936 96142 56500 57523 1...
output:
29798 11273 40142 68354 79772 18516 25710 47305 59942 26470 38196 38745 39903 71503 10201 26065 62767 44170 7161 62056 7829 13359 68362 6406 56500 57523 6629 21853 21246 52201 56121 2741 29933 72408 96953 849 22024 68285 86159 24582 9177 8756 52266 85993 1699 18069 29470 31014 36759 93564 3053 13483...
result:
wrong answer 1st lines differ - expected: '29798 11273 40142 68354 79772 ...6 42906 92073 84291 44638 91402', found: '29798 11273 40142 68354 79772 ... 42906 92073 84291 44638 91402 '