QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518891#7757. Palm IslandQFshengxiu#WA 1ms5876kbC++202.5kb2024-08-14 13:43:532024-08-14 13:43:53

Judging History

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

  • [2024-08-14 13:43:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5876kb
  • [2024-08-14 13:43:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define lowbit(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define inf 0x3f3f3f3f3f3f3f3f
#define int long long
#define pai 3.14
#define QF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
// #define width cout << ""
using ll = long long;
using PII = pair<int, int>;
using LD = long double;
mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
constexpr int N = 3e5 + 10;
map<int, int> mp;
int a[N], b[N];
void printer(list<int> v)
{
    cout << endl;
    for (auto x : v)
    {
        cout << x << " ";
    }
    cout << endl;
}
bool check(list<int> l)
{
    int cnt = 1;
    for (auto x : l)
    {
        if (x != b[cnt])
            return false;
        ++cnt;
    }
    return true;
}
void solve(int caseT)
{
    int n;
    cin >> n;
    list<int> l;
    set<PII> vis;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        l.push_back(a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        mp[b[i]] = i;
    }
    int cnt = 0;
    while (true)
    {

        list<int>::iterator it = l.begin();
        list<int>::iterator it2 = ++l.begin();
        list<int>::iterator it3 = --l.end();
        if (cnt >= n)
            break;
        if (mp[*(it3)] == mp[*(it)] - 1)
        {
            cnt++;
            l.push_back(*it);
            l.erase(it);
            cout << 1;
            if (check(l))
                break;
            continue;
        }
        if (mp[*(it3)] == mp[*(it2)] - 1)
        {
            cout << 2;
            cnt = 0;
            l.push_back(*it2);
            l.erase(it2);
            if (check(l))
                break;
            continue;
        }
        if (mp[*(it2)] < mp[*(it)] && !vis.count({*(it2), *(it)}))
        {
            cout << 2;
            cnt = 0;
            vis.insert({*(it2), *(it)});
            l.push_back(*it2);
            l.erase(it2);
        }
        else
        {
            cnt++;
            l.push_back(*it);
            l.erase(it);
            cout << 1;
        }
        // printer(l);
    }
}
signed main()
{
    QF;
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve(i);
        cout << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5876kb

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
1211
22111
221221
1221121111
11
11
112
22
11
21
22111
2
211
111
112
212111
1
1111
1221111
112111
212
211
2212111
2212
1
122122111
1111221
112111
2
2
212111
211
221111
21221111
2221121111
211
22111
2211
111
221
11
21
112
22
121121111
2
11
2122111
111
1121
1112
211
22111
221
12111
211
121221111
211...

result:

ok Correct. (200 test cases)

Test #3:

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

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:

122122111
11122111
222112111
22212122
2121221
122
121111
2112
212
12122111
1121
211221
1212122
211211122
11111
212111
11122
122
21211122
211211122
22211122
1122112111
222
111122111
22211122
111
2
121221
2122112111
2121111
121121111
21122111
22122
212211122
1121221
2111221
11121
1122111
11122
22121
2...

result:

ok Correct. (200 test cases)

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 5676kb

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:

112111
22112211111
211
21121111
122122212121111111111
212122122111121121111111121111111111
2111112211111111
112111
2111211111222111111
122112222122222111111
112111
2112111111
1222221222111111111
221211222111121111111
2
211
12122
12222222112222221111221111111111
2111211221111122221111111
222221111122...

result:

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