QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#634537#7757. Palm IslandBai_xiaobo#WA 1ms3808kbC++202.0kb2024-10-12 17:32:312024-10-12 17:32:32

Judging History

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

  • [2024-10-12 17:32:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3808kb
  • [2024-10-12 17:32:31]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define ll long long
#define endl "\n"
#define int long long
#define pr pair<int,int>
#define x first
#define y second
ll mod=1e9+7;

const ll N=1e3+10;
int a[N];
int b[N];
int l[N], r[N];
int suf[N];
int n;

void def(int s)
{
    r[l[s]] = r[s];
    l[r[s]] = l[s];
}

void ist(int s, int pre)
{
    r[s] = r[pre];
    l[s] = pre;
    r[l[s]] = s;
    l[r[s]] = s;
}

void solve()
{
    queue<int> ans;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        if (i == 1)
            l[a[i]] = a[n];
        else
            l[a[i]] = a[i - 1];
        r[a[i]] = a[(i % n) + 1];
    }
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    for (int i = 1; i <= n; i++)
        suf[b[i]] = b[(i % n) + 1];
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (r[a[i]] != suf[a[i]])
            cnt++;
    }
    int p = a[1];
    while (cnt > 0)
    {
        if (r[p] == suf[p])
        {
            p = r[p];
            ans.push(1);
            continue;
        }
        int s = suf[p];
        while (p != s)
        {
            p = r[p];
            ans.push(1);
        }
        if (r[p] == suf[p])
            cnt++;
        if (r[p] == suf[l[p]])
            cnt--;
        def(p);
        int pp = l[p];
        while (p != suf[pp])
        {
            pp = r[pp];
            ans.push(2);
        }
        ist(p, pp);
        cnt--;
        if (r[pp] == suf[pp])
            cnt--;
    }
    while (p != b[1])
    {
        p = r[p];
        ans.push(1);
    }
    while (!ans.empty())
    {
        cout << ans.front();
        ans.pop();
    }
    cout << '\n';
}

/*
1
4
 1 2 3 4
 2 1 3 4
*/

signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
}

详细

Test #1:

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

input:

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

output:

1
112211221

result:

ok Correct. (2 test cases)

Test #2:

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

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
1122111
111211
111121112221
111221112221
11
11
111221
1112111
11
112
111211
11211
1121
111
111221
11121122111
1

1122211222
11122
11121122
11221122
11122111
1111211122
1
11222111221122211
1111221
11122
11222112221122211
11211
11121122111
1121
111221112211
1112211122112221111
1111211222
1121
11121...

result:

ok Correct. (200 test cases)

Test #3:

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

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:

11222111221122211
11122111
11112112221111
11222111222111
1111211122112221111
11222112221
11222
112221112211222
1112211222112221111
111221122211
11122211
1122211122111
11112111221122211
111121112211222

11122112221122211
11122
11222112221
1111211122211
111121112211222
11222111221111
1112211122211
111...

result:

ok Correct. (200 test cases)

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3808kb

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:

1112221111
111222111122111222211111
1121
1122211122112221111
111111222211122222221111122222211222222221111222222
11112222221111111122111111222211111122221112222222111111111
1122222211222222111112221111222221
11122
1122222111122211122221112222
1112222211222222111222221111
11122
112222111122111222211
...

result:

wrong answer On Case#5: After your operations, a[2] = 4 but a[2] = 3. (test case 5)