結果
問題 | No.2107 Entangled LIS |
ユーザー | Seniorious |
提出日時 | 2022-11-28 15:42:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,847 bytes |
コンパイル時間 | 2,404 ms |
コンパイル使用メモリ | 206,300 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-10-05 14:07:58 |
合計ジャッジ時間 | 4,610 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 23 ms
6,816 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 43 ms
6,820 KB |
testcase_09 | AC | 44 ms
7,040 KB |
testcase_10 | AC | 25 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> #define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout) const int N = 200005; int main() { int T; scanf("%d", &T); while (T--) { int n, A, B; scanf("%d %d %d", &n, &A, &B); bool swap = false; static char ch[N]; scanf("%s", ch + 1); std::string str(ch + 1); if (A > B) { std::swap(A, B); for (int i = 0; i < n; ++i) str[i] = ((str[i] - 'a') ^ 1) + 'a'; swap = true; } std::vector<int> a(n + 1), b(n + 1); if (A == 1) { static int dp[N][2]; dp[0][str[0] - 'a'] = 1; for (int i = 1; i < n; ++i) { if (str[i] == 'b') { dp[i][1] = std::max(dp[i - 1][0], dp[i - 1][1]) + 1; dp[i][0] = dp[i - 1][0]; } else { dp[i][0] = dp[i - 1][0] + 1; dp[i][1] = dp[i - 1][1]; } } int l = std::max(dp[n - 1][0], dp[n - 1][1]); if (B > l) { puts("No"); continue; } int now = -1; for (int i = 0; i < n; ++i) { if (std::max(dp[i][0], dp[i][1]) == B) { now = i + 1; break; } } int cntnow = (n - now) * 2; for (int i = 0; i < now; ++i) { if (str[i] == 'a') b[i] = ++cntnow; } for (int i = now - 1; i >= 0; --i) a[i] = ++cntnow; for (int i = 0; i < now; ++i) { if (str[i] == 'b') b[i] = ++cntnow; } for (int i = now; i < n; ++i) { a[i] = (n - i) * 2, b[i] = (n - i) * 2 - 1; if (str[i] == 'b') std::swap(a[i], b[i]); } } else { int n1 = A - 2, n2 = B - A + 2, n3 = n - B; for (int i = 0; i < n1; ++i) { a[i] = i * 2 + 1, b[i] = i * 2 + 2; if (str[i] == 'a') std::swap(a[i], b[i]); } if (n2) { bool flag = true; for (int i = n1; i < n1 + n2 - 1; ++i) { if (str[i] == 'b' && str[i + 1] == 'a') flag = false; } int pos = n1; if (flag) { a[n1] = n1 * 2 + 1, b[n1] = n1 * 2 + 2; if (str[n1] == 'a') std::swap(a[n1], b[n1]); ++pos; } int nowpos = 2 * pos; for (int i = pos; i < n1 + n2; ++i) { if (str[i] == 'b') a[i] = ++nowpos; } for (int i = pos; i < n1 + n2; ++i) b[i] = ++nowpos; for (int i = pos; i < n1 + n2; ++i) { if (str[i] == 'a') a[i] = ++nowpos; } } for (int i = 0; i < n1 + n2; ++i) a[i] += n3 * 2, b[i] += n3 * 2; for (int i = n1 + n2; i < n; ++i) { a[i] = (n - i) * 2, b[i] = (n - i) * 2 - 1; if (str[i] == 'b') std::swap(a[i], b[i]); } } puts("Yes"); if (swap) std::swap(a, b); for (int i = 0; i < n; ++i) printf("%d%c", a[i], " \n"[i == n - 1]); for (int i = 0; i < n; ++i) printf("%d%c", b[i], " \n"[i == n - 1]); } return 0; }