QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#409032 | #6366. Message | iee | RE | 15ms | 199376kb | C++17 | 910b | 2024-05-11 16:14:50 | 2024-05-11 16:14:51 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N = 5005;
char s[N], t[N];
int f[N][N];
int n, m, w[N];
int fir[26], las[26];
void cmin(int &x, int y) {
if (y < x) x = y;
}
signed main() {
cin >> (s + 1) >> (t + 1), n = strlen(s + 1), m = strlen(t + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
fill(fir, fir + 26, 1e9);
for (int i = 1; i <= m; i++) {
if (fir[t[i] - 'a'] == 1e9) fir[t[i] - 'a'] = i;
las[t[i] - 'a'] = i;
}
memset(f, 0x3f, sizeof f);
f[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= m; j++) {
if (j < m && t[j + 1] == s[i + 1]) cmin(f[i + 1][j + 1], f[i][j]);
if (j < fir[s[i + 1] - 'a'] || j >= las[s[i + 1] - 'a']) cmin(f[i + 1][j], f[i][j] + w[i + 1]);
}
}
if (f[n][m] > 1e18) cout << "You better start from scratch man..." << "\n";
else cout << f[n][m] << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 15ms
memory: 199376kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 3ms
memory: 199300kb
input:
babab baab 2 1 3 2 4
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #3:
score: -100
Runtime Error
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...