QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#409020#6366. MessageieeRE 8ms199428kbC++17905b2024-05-11 15:50:572024-05-11 15:50:57

Judging History

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

  • [2024-05-11 15:50:57]
  • 评测
  • 测评结果:RE
  • 用时:8ms
  • 内存:199428kb
  • [2024-05-11 15:50:57]
  • 提交

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;
}

詳細信息

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

output:


result: