QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619662#7757. Palm Island333zhan#TL 1ms3684kbC++202.2kb2024-10-07 14:56:382024-10-07 14:56:43

Judging History

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

  • [2024-10-07 14:56:43]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3684kb
  • [2024-10-07 14:56:38]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve () {
    int n;
    cin >> n;

    vector <int> a (n), b (n);
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i ++) {
        cin >> b[i];
    }

    if (a == b) {
        cout << '\n';
        return;
    }

    vector <int> nxt (n + 1);
    for (int i = 0; i < n; i ++) {
        nxt[b[i]] = b[(i + 1) % n];
    }

    deque <int> q;
    for (int i = 0; i < n; i ++) {
        q.push_back (a[i]);
    }

    int ttt = 0;

    vector <int> oper; 
    while (true) {
        int cnt = 0;
        while (nxt[q[0]] == q[1]) {
            int x = q[0];
            q.pop_front ();
            q.push_back (x);
            x = q[0];
            q.pop_front ();
            q.push_back (x);
            cnt += 2;
            oper.push_back (1);
            oper.push_back (1);
            if (cnt == (n & 1 ? n * 2 : n)) {
                break;
            }
        }
        if (cnt == (n & 1 ? n * 2 : n)) {
            for (int j = 0; j < cnt; j ++) {
                oper.pop_back ();
            }
            break;
        }
        int x = q[0];
        q.pop_front ();
        while (q[0] != nxt[x]) {
            oper.push_back (2);
            int y = q[0];
            q.pop_front ();
            q.push_back (y);
        }
        q.push_back (x);
        x = q[0];
        q.pop_front ();
        q.push_back (x);
        oper.push_back (1);
        oper.push_back (1);
        // ttt ++;
        // if (ttt == 11) {
        //     break;
        // }
        // for (auto x : q) {
        //     cerr << x << " \n"[x == q.back ()]; 
        // }
    }

    // for (auto x : q) {
    //     cerr << x << " ";
    // }

    while (q[0] != b[0]) {
        oper.push_back (1);
        int x = q[0];
        q.pop_front ();
        q.push_back (x);
    }

    // cerr << oper.size () << '\n';
    for (auto x : oper) {
        cout << x;
    }    
    cout << '\n';
}

signed main () {
    ios::sync_with_stdio (false);
    cin.tie (nullptr);

    int T = 1;
    cin >> T;

    while (T --) {
        solve ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

2
3
1 2 3
2 3 1
4
1 2 3 4
2 1 3 4

output:

1
2111

result:

ok Correct. (2 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

200
3
3 1 2
2 3 1
4
2 4 1 3
2 1 4 3
4
1 4 2 3
2 1 3 4
5
4 3 2 1 5
2 4 5 3 1
5
2 1 5 4 3
5 2 4 1 3
4
4 3 1 2
1 2 4 3
3
1 2 3
3 1 2
4
1 4 2 3
2 1 4 3
4
1 3 2 4
1 4 3 2
3
3 2 1
1 3 2
3
2 3 1
1 3 2
4
1 4 3 2
3 1 2 4
3
1 2 3
1 3 2
3
3 2 1
2 3 1
5
5 1 3 2 4
2 4 5 1 3
4
4 3 1 2
1 4 3 2
4
1 3 4 2
2 4 3 1
3
...

output:

11
211211111
22111
22211211112211111
22112111111
11
11
1121111
221111
11
21111
22111
2111
211
111
1121111
2211211
1

2112111122111
112111
22112111
211
11211
22211112211111
1
211211
111122111111
112111
211111
2111
2211211
211
221111
22112111122111
2221121111
211
22111
2211
111
2211111
11
2111111
1121...

result:

ok Correct. (200 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

200
5
5 1 3 4 2
5 3 2 4 1
5
5 1 2 4 3
3 5 4 1 2
5
1 4 5 3 2
2 5 4 3 1
5
1 5 4 3 2
4 5 2 3 1
5
2 3 4 5 1
5 4 3 2 1
5
1 5 2 4 3
5 3 1 2 4
5
1 2 4 3 5
4 2 3 5 1
5
3 2 1 4 5
4 2 3 1 5
5
3 1 2 5 4
2 4 1 3 5
5
5 3 1 4 2
2 5 4 1 3
5
5 4 3 1 2
2 5 4 1 3
5
3 4 5 2 1
3 5 1 4 2
5
4 5 1 3 2
4 2 3 1 5
5
1 3 4 5 ...

output:

211211
22112211111
222112111
21122112111122111
22211221121111221111
21121111221111
21111221111
211211111
2211112211111
221122112111122111111
112111111
21122111111
222112211211112211
222112211211112211111

22111122111
22112211
21121111221111
222112111122111111
222112211211112211111
2112211
2211211
22...

result:

ok Correct. (200 test cases)

Test #4:

score: -100
Time Limit Exceeded

input:

100
5
1 2 5 4 3
2 4 5 3 1
6
6 1 5 2 4 3
1 4 5 6 2 3
3
2 1 3
1 2 3
5
5 3 4 2 1
1 2 3 5 4
10
5 9 4 2 6 10 7 8 3 1
1 3 4 10 5 7 2 9 8 6
10
5 9 10 7 8 3 4 6 2 1
2 7 4 3 10 9 5 8 1 6
8
1 7 4 6 3 5 2 8
3 5 1 4 6 8 7 2
4
2 3 4 1
1 4 2 3
7
3 7 4 6 2 1 5
5 6 7 3 4 1 2
8
2 1 4 7 8 3 6 5
5 2 7 4 3 1 8 6
4
3 2 ...

output:


result: