QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246485 | #4666. Delete And Win | LCX756 | WA | 0ms | 3960kb | C++20 | 1.3kb | 2023-11-10 21:00:32 | 2023-11-10 21:00:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define fir first
#define sec second
#ifdef LCX
#define msg(args...) void(fprintf(stderr, args))
#else
#define msg(...) void()
#endif
const int maxn = 1e5 + 10, C = 26, inf = 1e9;
int n, m, nxt[maxn][C];
char s[maxn], t[maxn];
int main() {
// freopen("string.in", "r", stdin), freopen("string.out", "w", stdout);
scanf("%s%s", s + 1, t + 1);
n = strlen(s + 1), m = strlen(t + 1);
for (int i = m + 1; i >= 0; --i) {
for (int j = 0; j < C; ++j) {
if (i == m + 1) nxt[i][j] = m + 1;
else if (i < m && t[i + 1] == j + 'a') nxt[i][j] = i + 1;
else nxt[i][j] = nxt[i + 1][j];
}
}
int ans = inf, p = 0, cnt = 0;
for (int i = 1; i <= n; ++i) {
ans = min(ans, cnt + m - p);
for (int c = 0; c < s[i] - 'a'; ++c)
ans = min(ans, cnt + nxt[p][c] - p - 1);
int np = nxt[p][s[i] - 'a'];
cnt += np - p - 1, p = np;
if (p > m) { ans = min(ans, cnt); break; }
}
printf("%d\n", ans);
return 0;
}
/*
pqsrpspqz
pqrpqz
0
*/
/*
whqwillsingatninem
dajiabujianbusan
0
*/
/*
ahhhhhhhhhhhhhhflowerletterishuahua
heisanoierinhighschoolaffiliatedtorenminuniversityofchina
7
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3960kb
input:
pqsrpspqz pqrpqz
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'