QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246252 | #4669. Genetic Modifications | Leasier | WA | 0ms | 3640kb | C++98 | 2.3kb | 2023-11-10 17:55:40 | 2023-11-10 17:55:41 |
Judging History
answer
#include <stdio.h>
#include <string.h>
typedef struct Segment_tag {
int l;
int r;
Segment_tag(){}
Segment_tag(int l_, int r_){
l = l_;
r = r_;
}
inline bool contain(int x){
return l <= x && x <= r;
}
} Segment;
int L = -1, R;
Segment global;
int l[100007], pre[100007][7], nxt[100007][7], ans[100007];
char s[100007], t[100007];
Segment dp[100007];
inline int min(int a, int b){
return a < b ? a : b;
}
inline int max(int a, int b){
return a > b ? a : b;
}
Segment operator |(const Segment a, const Segment b){
if (a.l > a.r) return b;
if (b.l > b.r) return a;
return Segment(min(a.l, b.l), max(a.r, b.r));
}
void operator |=(Segment &a, const Segment b){
a = a | b;
}
inline void move(int l, int r){
if (L < l){
L = l;
R = l - 1;
global = Segment(1e9, 0);
}
while (R < r) global |= dp[++R];
}
inline void normalize(Segment &seg, int ch){
if (seg.l > seg.r) return;
seg.l = nxt[seg.l][ch];
seg.r = pre[seg.r][ch];
}
int main(){
int n, m, mi, pos;
bool flag = true;
scanf("%s %s", &s[1], &t[1]);
n = strlen(&s[1]);
m = strlen(&t[1]);
mi = m + 1;
for (int i = 1; i <= n; i++){
l[i] = s[i] == s[i - 1] ? l[i - 1] : i;
}
for (int i = 1; i <= m; i++){
for (int j = 0; j <= 1; j++){
pre[i][j] = t[i] - 'A' == j ? i : pre[i - 1][j];
}
}
for (int i = 0; i <= 1; i++){
nxt[mi][i] = mi;
}
for (int i = m; i >= 1; i--){
for (int j = 0; j <= 1; j++){
nxt[i][j] = t[i] - 'A' == j ? i : nxt[i + 1][j];
}
}
dp[0] = Segment(1e9, 0);
for (int i = 1; i <= n; i++){
if (flag && s[i] == t[1]){
dp[i] = Segment(1, 1);
} else {
dp[i] = Segment(1e9, 0);
}
move(max(l[i - 1] - 1, 0), i - 1);
dp[i] |= Segment(global.l + 1, min(global.r + 1, m));
normalize(dp[i], s[i] - 'A');
flag &= s[i] == s[1];
}
pos = n;
flag = true;
while (pos >= 1){
if (s[pos] == t[m] && dp[pos].contain(m)) break;
if (s[pos] != s[n]){
flag = false;
break;
}
pos--;
}
if (pos == 0 || !flag){
printf("NO");
return 0;
}
printf("YES\n");
for (int i = pos, j = m; j >= 1; j--){
ans[j] = i;
if (j == 1) break;
do {
i--;
} while (s[i] != t[j - 1] || dp[i].contain(j - 1));
}
for (int i = 1; i <= m; i++){
printf("%d ", ans[i]);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3640kb
input:
BBAAABBAAABAAA BAAB
output:
YES 7 9 10 11
result:
wrong answer wrong solution [2]