QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#112604 | #4422. Two Permutations | Tobo | AC ✓ | 3604ms | 83088kb | C++20 | 1.0kb | 2023-06-12 15:07:05 | 2023-06-12 15:07:09 |
Judging History
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