QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245947 | #4669. Genetic Modifications | sherman2023 | WA | 1ms | 8068kb | C++14 | 3.8kb | 2023-11-10 14:45:03 | 2023-11-10 14:45:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5, N1 = 2000 + 5;
int n, m;
int f[N1][N1], sum[N];
int g[N1][N1];
int nex[N], op[N], tot = 0;
int f2[N][25], g2[N][25];
char s[N], t[N];
void DFS(int x, int y) {
if(x == 0) return;
for(int i = x - 1; i >= nex[x - 1] - 1; -- i) {
if(f[i][y - 1]) {
DFS(i, y - 1);
break;
}
}
op[++ tot] = x;
printf("%d ", x);
}
void DFS2(int x, int y) {
if(x == 0) return;
for(int i = x - 1; i >= nex[x - 1] - 1; -- i) {
if(f2[i][y - 1]) {
DFS(i, y - 1);
break;
}
}
op[++ tot] = x;
printf("%d ", x);
}
int main() {
// freopen("sequence.in", "r", stdin);
// freopen("sequence.out", "w", stdout);
scanf("%s", s + 1);
scanf("%s", t + 1);
n = strlen(s + 1), m = strlen(t + 1);
int p = 1;
for(int i = 1; i < m; ++ i) {
if(t[i] == t[i + 1]) p = 0;
}
if(n <= 2000) {
sum[0] = 0;
for(int i = 1; i <= n; ++ i) sum[i] = sum[i - 1] + s[i] - 'A';
nex[1] = 1;
for(int i = 2; i <= n; ++ i) {
if(s[i] == s[i - 1]) nex[i] = nex[i - 1];
else nex[i] = i;
}
f[0][0] = 1, g[0][0] = 1;
for(int i = 1; i <= n; ++ i) g[i][0] = g[i - 1][0] + f[i][0];
for(int i = 1; i <= m; ++ i) {
for(int j = 1; j <= n; ++ j) {
if(s[j] != t[i]) continue;
if(nex[j - 1] - 1 > 0) f[j][i] = g[j - 1][i - 1] - g[nex[j - 1] - 2][i - 1];
else f[j][i] = g[j - 1][i - 1];
if(f[j][i]) f[j][i] = 1;
}
g[0][i] = f[0][i];
for(int j = 1; j <= n; ++ j) g[j][i] = g[j - 1][i] + f[j][i];
}
for(int i = n; i >= 1; -- i) {
if(f[i][m] == 1 && (sum[n] - sum[i] == 0 || sum[n] - sum[i] == n - i)) {
puts("YES");
DFS(i, m);
int isok = 1;
for(int j = 1; j <= tot; ++ j) {
if(s[op[j]] != t[j] || op[j - 1] < nex[op[j] - 1] - 1) isok = 0;
}
return 0;
}
}
puts("NO");
return 0;
}
if(n <= 100000 && m <= 20) {
sum[0] = 0;
for(int i = 1; i <= n; ++ i) sum[i] = sum[i - 1] + s[i] - 'A';
nex[1] = 1;
for(int i = 2; i <= n; ++ i) {
if(s[i] == s[i - 1]) nex[i] = nex[i - 1];
else nex[i] = i;
}
f2[0][0] = 1, g2[0][0] = 1;
for(int i = 1; i <= n; ++ i) g2[i][0] = g2[i - 1][0] + f2[i][0];
for(int i = 1; i <= m; ++ i) {
for(int j = 1; j <= n; ++ j) {
if(s[j] != t[i]) continue;
if(nex[j - 1] - 1 > 0) f2[j][i] = g2[j - 1][i - 1] - g2[nex[j - 1] - 2][i - 1];
else f2[j][i] = g2[j - 1][i - 1];
if(f2[j][i]) f2[j][i] = 1;
}
g2[0][i] = f2[0][i];
for(int j = 1; j <= n; ++ j) g2[j][i] = g2[j - 1][i] + f2[j][i];
}
for(int i = n; i >= 1; -- i) {
if(f[i][m] == 1 && (sum[n] - sum[i] == 0 || sum[n] - sum[i] == n - i)) {
puts("YES");
DFS2(i, m);
return 0;
}
}
puts("NO");
return 0;
}
if(p) {
sum[0] = 0;
for(int i = 1; i <= n; ++ i) sum[i] = sum[i - 1] + s[i] - 'A';
int las = 0;
tot = 0;
for(int i = 1; i <= n; ++ i) {
if(sum[i - 1] - sum[las] == 0 || sum[i - 1] - sum[las] == i - 1 - las) {
if(s[i] == t[tot + 1]) {
tot ++;
op[tot] = i;
las = i;
}
}
}
if(sum[n] - sum[las] == 0 | sum[n] - sum[las] == n - las) {
if(tot == m) {
puts("YES");
for(int i = 1; i <= tot; ++ i) printf("%d ", op[i]);
return 0;
}
}
las = 0, tot = 0;
int fi = 1;
for(int i = 1; i <= n; ++ i) {
if(fi == 1 && s[i] == t[tot + 1]) continue;
if(s[i] != t[tot + 1]) {
fi = 0;
continue;
}
if(sum[i - 1] - sum[las] == 0 || sum[i - 1] - sum[las] == i - 1 - las) {
tot ++;
op[tot] = i;
las = i;
}
}
if(sum[n] - sum[las] == 0 | sum[n] - sum[las] == n - las) {
if(tot == m) {
puts("YES");
for(int i = 1; i <= tot; ++ i) printf("%d ", op[i]);
return 0;
}
}
puts("NO");
return 0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8068kb
input:
BBAAABBAAABAAA BAAB
output:
YES 2 5 8 11
result:
ok good solution
Test #2:
score: 0
Accepted
time: 1ms
memory: 7980kb
input:
ABABABABAB ABAB
output:
NO
result:
ok no solution
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3860kb
input:
BBAAAAABBAAAAAABBABAABBBBBAABBBAAABABBABABBBAAABBAAAABBBBBABAABBBAABBBBBBBABBABABBAAAABBAAAABAAAABBABAAAAAAABBBBAAAAAABAABABBAAAAABBBBAABABABAAAAABBBABABBAABABBBBAABAABBBBBABBABABBAAABBAAAABBBABBABAAAABBBAABAAABBBAAAAAAAAAAAAABABBAABBBBABABAABBBBABAABBAAABABBBBAAAAAAAABBAAAABBABABABBBAAABAABBABBAAAA...
output:
result:
wrong output format Unexpected end of file - token expected