QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409020 | #6366. Message | iee | RE | 8ms | 199428kb | C++17 | 905b | 2024-05-11 15:50:57 | 2024-05-11 15:50:57 |
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(las, las + 26, 1e9);
for (int i = 1; i <= m; i++) {
if (!fir[t[i] - 'a']) 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 199428kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 8ms
memory: 199296kb
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...