QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#119109#6680. HeappropaneAC ✓109ms4152kbC++202.1kb2023-07-04 22:44:542023-07-04 22:44:57

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-04 22:44:57]
  • 评测
  • 测评结果:AC
  • 用时:109ms
  • 内存:4152kb
  • [2023-07-04 22:44:54]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    const int INF = 0x3f3f3f3f;

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vector<int> a(n + 1), b(n + 1);
        for(int i = 1; i <= n; i++) cin >> a[i];
        for(int i = 1; i <= n; i++) cin >> b[i];
        string ans;
        for(int i = n; i >= 1; i--){
            int cur = i;
            int mx = 0, mn = INF;
            while(cur && b[cur] != a[i]){
                mx = max(mx, b[cur]);
                mn = min(mn, b[cur]);
                cur /= 2;
            }
            if (cur == 0){
                ans.clear();
                break;
            }
            if (cur == i){
                if (cur / 2 != 0 && b[cur / 2] > a[i]){
                    ans += "1";
                }
                else{
                    ans += "0";
                }
            }
            else if (a[i] > mx){
                if (cur / 2 != 0 && b[cur / 2] < a[i]){
                    ans.clear();
                    break;
                }
                ans += "1";
                int t = i, bk = b[t];
                while(t != cur){
                    swap(bk, b[t / 2]);
                    t /= 2;
                }
            }
            else if (a[i] < mn){
                if (cur / 2 != 0 && b[cur / 2] > a[i]){
                    ans.clear();
                    break;
                }
                ans += "0";
                int t = i, bk = b[t];
                while(t != cur){
                    swap(bk, b[t / 2]);
                    t /= 2;
                }
            }
            else{
                ans.clear();
                break;
            }
        }
        reverse(ans.begin(), ans.end());
        if (ans.empty()) cout << "Impossible" << '\n';
        else cout << ans << '\n';
    }

}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3432kb

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
Impossible
001

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 102ms
memory: 4128kb

input:

1118
77
210555 375330 669075 785279 194474 310626 830710 886719 102133 426324 41900 971872 167203 702222 230534 112350 673156 358623 886831 72864 818751 367894 842740 531878 818794 131219 412128 104469 70427 658494 72060 768735 915294 161365 91671 451974 121863 498890 408674 670274 875754 967228 518...

output:

00010111111010100000101000101001111010010000100101001001001000001100111100010
000001011011010
01011011111111010011000100101100101010000110111000001100
0
Impossible
01
011001000010010011110011010100110010111110101000010001101101000011
Impossible
Impossible
010001111
0010000101001000000100110111100111...

result:

ok 1118 lines

Test #3:

score: 0
Accepted
time: 109ms
memory: 4152kb

input:

1119
77
108375330 409310626 560194474 108375330 89669075 89669075 409310626 477785279 89669075 89669075 89669075 477785279 108375330 89669075 409310626 560194474 108375330 89669075 108375330 89669075 477785279 89669075 108375330 108375330 409310626 108375330 477785279 89669075 477785279 477785279 10...

output:

00110111001111011101000101101101100100010000001011100010000000001010101011000
00011
000000000000000000000000000000000000000000000000000000000000000000000000000000000000
01110001101010100000000010011010110010001000001110100000010010000001101100001001000001
Impossible
Impossible
0110000001101001110110...

result:

ok 1119 lines