QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246145 | #4669. Genetic Modifications | Nightmare07 | WA | 2ms | 9796kb | C++14 | 2.6kb | 2023-11-10 16:33:22 | 2023-11-10 16:33:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 2010;
const int K = 25;
int n, m, tmp;
int f[N], Pre[N], G[M][M], G_[N][K], c[N];
bool dp[M][M], dp_[N][K];
char a[N], b[N];
int Find(int x) {
if (f[x] != x) f[x] = Find(f[x]);
return f[x];
}
int main() {
scanf("%s%s", a + 2, b + 2);
n = strlen(a + 2), m = strlen(b + 2);
a[1] = b[1] = '2';
n += 2, m += 2;
a[n] = b[m] = '2';
for (int i = 1; i <= n; i ++) f[i] = i;
for (int i = 2; i <= n; i ++)
if (a[i - 1] == a[i]) {
int fx = Find(i - 1), fy = Find(i);
f[fy] = fx;
}
for (int i = 1; i <= n; i ++) {
if (i == 1) Pre[i] = 1;
else if (a[i - 1] == a[i]) Pre[i] = max(1, Find(i) - 1);
else Pre[i] = max(1, Find(i - 1) - 1);
}
if (n <= 2000) {
dp[1][1] = 1;
for (int j = 2; j <= m; j ++) {
int cnt = 0;
dp[1][j] = 0;
queue<int> q;
for (int i = 2; i <= n; i ++) {
if (dp[i - 1][j - 1]) q.push(i - 1);
if (a[i] == b[j]) {
while (q.size() && q.front() < Pre[i]) q.pop();
if (q.size()) dp[i][j] = 1, G[i][j] = q.front();
}
}
}
int Id = 0;
for (int i = 1; i <= n; i ++) {
if (dp[i][m]) {
Id = i;
break;
}
}
if (!Id) puts("NO");
else {
puts("YES");
stack<int> s;
for (int i = m; i >= 1; i --) {
s.push(Id);
Id = G[Id][i];
if (i == 1) break;
}
s.pop();
while (s.size() > 1) {
printf("%d ", s.top() - 1);
s.pop();
}
}
return 0;
}
if (m <= 20) {
dp_[1][1] = 1;
for (int j = 2; j <= m; j ++) {
int cnt = 0;
dp_[1][j] = 0;
queue<int> q;
for (int i = 2; i <= n; i ++) {
if (dp_[i - 1][j - 1]) q.push(i - 1);
if (a[i] == b[j]) {
while (q.size() && q.front() < Pre[i]) q.pop();
if (q.size()) dp_[i][j] = 1, G_[i][j] = q.front();
}
}
}
int Id = 0;
for (int i = 1; i <= n; i ++) {
if (dp_[i][m]) {
Id = i;
break;
}
}
if (!Id) puts("NO");
else {
puts("YES");
stack<int> s;
for (int i = m; i >= 1; i --) {
s.push(Id);
Id = G_[Id][i];
if (i == 1) break;
}
s.pop();
while (s.size() > 1) {
printf("%d ", s.top() - 1);
s.pop();
}
}
return 0;
}
c[1] = 1, tmp = 1;
for (int i = 2; i <= n; i ++)
if (a[i] != a[i - 1]) c[++ tmp] = i;
if (a[1] != b[1]) {
if (tmp - 1 >= m) {
puts("YES");
for (int i = 2; i <= m + 1; i ++) printf("%d ", c[i]);
}
else puts("NO");
}
else {
if (tmp >= m) {
puts("YES");
for (int i = 1; i <= m; i ++) printf("%d ", c[i]);
}
else puts("NO");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9796kb
input:
BBAAABBAAABAAA BAAB
output:
YES 2 5 8 11
result:
ok good solution
Test #2:
score: 0
Accepted
time: 1ms
memory: 7656kb
input:
ABABABABAB ABAB
output:
NO
result:
ok no solution
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 8004kb
input:
BBAAAAABBAAAAAABBABAABBBBBAABBBAAABABBABABBBAAABBAAAABBBBBABAABBBAABBBBBBBABBABABBAAAABBAAAABAAAABBABAAAAAAABBBBAAAAAABAABABBAAAAABBBBAABABABAAAAABBBABABBAABABBBBAABAABBBBBABBABABBAAABBAAAABBBABBABAAAABBBAABAAABBBAAAAAAAAAAAAABABBAABBBBABABAABBBBABAABBAAABABBBBAAAAAAAABBAAAABBABABABBBAAABAABBABBAAAA...
output:
YES 1 2 4 9 11 17 19 20 21 23 28 30 33 36 37 38 40 41 42 43 46 49 51 55 60 61 62 64 67 69 76 77 79 80 81 82 84 88 90 94 95 99 101 102 103 110 114 120 121 123 124 125 127 132 136 138 139 140 141 142 143 148 151 152 153 154 156 158 159 160 164 166 167 169 174 175 177 178 179 180 182 185 187 191 194 19...
result:
wrong answer wrong solution [1]