QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112604#4422. Two PermutationsToboAC ✓3604ms83088kbC++201.0kb2023-06-12 15:07:052023-06-12 15:07:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-12 15:07:09]
  • 评测
  • 测评结果:AC
  • 用时:3604ms
  • 内存:83088kb
  • [2023-06-12 15:07:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define N 300005
#define mod 998244353

int n, a[N], b[N], c[N << 1];
void solve()
{
    cin >> n;
    for (int i = 1, x; i <= n; i++)
    {
        cin >> x;
        a[x] = i;
    }
    for (int i = 1, x; i <= n; i++)
    {
        cin >> x;
        b[x] = i;
    }
    for (int i = 1; i <= n * 2; i++)
        cin >> c[i];
    map<pair<int, int>, int> dp;
    dp[{0, 0}] = 1;
    for (int i = 1; i <= n * 2; i++)
    {
        int lena = a[c[i]];
        int lenb = i - lena;
        if (dp.count({lena - 1, lenb}))
            dp[{lena, lenb}] = (dp[{lena, lenb}] + dp[{lena - 1, lenb}]) % mod;
        lenb = b[c[i]];
        lena = i - lenb;
        if (dp.count({lena, lenb - 1}))
            dp[{lena, lenb}] = (dp[{lena, lenb}] + dp[{lena, lenb - 1}]) % mod;
    }
    cout << dp[{n, n}] << '\n';
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

详细

Test #1:

score: 100
Accepted
time: 3604ms
memory: 83088kb

input:

282
1000
434 697 735 906 614 835 227 800 116 98 776 601 110 371 262 452 608 368 719 717 241 572 203 410 440 749 604 457 516 637 488 691 841 493 418 307 745 499 833 789 819 179 357 288 129 954 29 391 80 389 771 613 653 747 928 570 518 1000 547 587 727 778 669 554 426 899 256 681 515 532 409 677 533 3...

output:

4
2
16
2
2
2
1
1
8
8
4
4
2
2
2
1
2
2
2
2
2
1
1
2
8
1
2
2
4
2
2
1
2
2
8
2
2
2
4
4
1
4
1
4
4
1
1
8
4
0
4
4
1
2
4
2
2
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 282 lines