QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121603#6680. HeapNicolas125841WA 0ms3404kbC++172.7kb2023-07-08 15:24:102023-07-08 15:24:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 15:24:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3404kb
  • [2023-07-08 15:24:10]
  • 提交

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'