QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634512#7757. Palm IslandBai_xiaobo#WA 0ms3816kbC++201.9kb2024-10-12 17:29:282024-10-12 17:29:29

Judging History

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

  • [2024-10-12 17:29:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-10-12 17:29:28]
  • 提交

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[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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3816kb

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
1122211222111
11211
11121122111
1121
111221112211
1112211122
1111211222
1121
111211
11121
111
1...

result:

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