QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#121603 | #6680. Heap | Nicolas125841 | WA | 0ms | 3404kb | C++17 | 2.7kb | 2023-07-08 15:24:10 | 2023-07-08 15:24:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> v(n), a(n), oa(n);
for(int i = 0; i < n; i++)
cin >> v[i];
for(int i = 0; i < n; i++){
cin >> a[i];
oa[i] = a[i];
}
string bs;
vector<int> inds;
bool good = true, found = false;
n--;
while(n > 0){
int ind = n;
char type;
if(a[ind] == v[n]){
assert(a.back() == v[n]);
if(a[(ind-1)/2] <= v[n])
bs.push_back('0');
else
bs.push_back('1');
a.pop_back();
n--;
continue;
}else if(a[ind] < v[n])
type = '1';
else
type = '0';
found = false;
inds.clear();
inds.push_back(ind);
do{
ind = (ind-1)/2;
inds.push_back(ind);
if(a[ind] == v[n]){
found = true;
if(ind > 0){
if(a[(ind-1)/2] < v[n])
if(type == '1')
good = false;
else if(a[(ind-1)/2] > v[n])
if(type == '0')
good = false;
}
break;
}else if(a[ind] < v[n]){
if(type == '0'){
good = false;
break;
}
}else{
if(type == '1'){
good = false;
break;
}
}
}while(ind > 0);
if(!good || !found){
good = false;
break;
}
for(int i = inds.size()-2; i >= 0; i--)
swap(a[inds[i]], a[inds[i+1]]);
assert(a.back() == v[n]);
bs.push_back(type);
a.pop_back();
n--;
}
if(a.back() != v[0])
good = false;
bs.push_back('0');
a.pop_back();
reverse(bs.begin(), bs.end());
if(!good && n == 0 && a.size() == 0)
cout << "Impossible\n";
else
cout << bs << "\n";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3404kb
input:
3 4 2 3 1 4 4 1 3 2 5 4 5 1 2 3 3 4 1 5 2 3 1 1 2 2 1 1
output:
0101 0 001
result:
wrong answer 2nd lines differ - expected: 'Impossible', found: '0'