QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#409032#6366. MessageieeRE 15ms199376kbC++17910b2024-05-11 16:14:502024-05-11 16:14:51

Judging History

你现在查看的是最新测评结果

  • [2024-05-11 16:14:51]
  • 评测
  • 测评结果:RE
  • 用时:15ms
  • 内存:199376kb
  • [2024-05-11 16:14:50]
  • 提交

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...

output:


result: