QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645016 | #6366. Message | PPPxvchongyv | WA | 164ms | 13552kb | C++14 | 2.4kb | 2024-10-16 16:30:09 | 2024-10-16 16:30:09 |
Judging History
answer
#include <bits/stdc++.h>
std::vector<int> KMPed(const std::string &a, std::string g) {
g = '`' + g;
std::vector<int> b(g.length(), 0);
b[0] = -1;
for(int i = 1; i < g.length(); i++) {
int p = b[i - 1];
while(p != -1)
if(g[p + 1] != g[i])
p = b[p];
else
break;
b[i] = p + 1;
}
std::vector<int> res;
int k = 0;
for(int i = 0; i < a.length(); i++) {
while(k >= 0 && a[i] != g[k + 1])
k = b[k];
k++;
if(k == g.length() - 1)
res.push_back(i), k = b[k];
}
return res;
}
constexpr long long Inf = 3141592653589793238LL;
char a[262144], b[262144];
int n, m, t[262144];
long long st[262144];
std::array<int, 32> bl, br;
std::array<long long, 262144> f, g;
std::vector<int> u;
int main() {
scanf("%s%s", a + 1, b + 1), n = strlen(a + 1), m = strlen(b + 1);
for(int i = 1; i <= n; i++)
a[i] -= '`';
for(int i = 1; i <= m; i++)
b[i] -= '`';
for(int i = 1; i <= n; i++)
scanf("%d", &t[i]);
bl.fill(m), br.fill(1);
for(int i = 1; i <= m; i++)
bl[b[i]] = std::min(bl[b[i]], i),
br[b[i]] = std::max(br[b[i]], i);
for(int i = 0; i <= 26; i++)
u.push_back(bl[i]), u.push_back(br[i] + 1);
std::sort(u.begin(), u.end()),
u.erase(std::unique(u.begin(), u.end()), u.end());
f[0] = -Inf;
for(int j = 1; j <= n; j++)
f[j] = std::min(f[j], f[j - 1] + t[j]);
for(int i = 1; i < u.size(); i++) {
std::string filt;
std::bitset<32> has;
std::vector<int> filtered;
for(int j = 1; j <= 26; j++)
has[j] = bl[j] <= u[i - 1] && u[i] - 1 <= br[j];
for(int j = 1; j <= n; j++)
if(has[a[j]])
filt.push_back(a[j]), filtered.push_back(j);
for(int j = 1; j <= n; j++)
st[j] = st[j - 1] + (has[a[j]] ? 0 : t[j]);
for(int j = 1; j <= n; j++)
if(!has[a[j]] || bl[j] == u[i - 1])
f[j] = std::min(f[j], f[j - 1] + t[j]);
std::vector<int> yes = KMPed(filt, std::string(b + u[i - 1], b + u[i]));
g.fill(0);
for(int j : yes) {
int l = filtered[j + u[i - 1] - u[i] + 1] - 1, r = filtered[j];
g[r] = std::min(g[r], f[l] + st[r] - st[l]);
}
std::swap(f, g);
for(int j = 1; j <= n; j++)
if(!has[a[j]] || br[j] + 1 == u[i])
f[j] = std::min(f[j], f[j - 1] + t[j]);
}
for(int j = 1; j <= n; j++)
f[j] = std::min(f[j], f[j - 1] + t[j]);
if(f[n] < 0)
printf("%lld\n", f[n] + Inf);
else
printf("You better start from scratch man...\n");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11384kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9540kb
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: 0
Accepted
time: 27ms
memory: 13036kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #4:
score: 0
Accepted
time: 50ms
memory: 13324kb
input:
bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #5:
score: 0
Accepted
time: 164ms
memory: 13552kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #6:
score: 0
Accepted
time: 23ms
memory: 13360kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 101ms
memory: 13232kb
input:
hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 153ms
memory: 13420kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 10216kb
input:
aaaaaaaaaa a 670064684 12247274 885150692 755303894 373857482 772871474 451986656 733926307 275101324 732261937
output:
4777621032
result:
ok single line: '4777621032'
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 10380kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa 807194254 763061330 636628022 447638039 310117480 873320507 134259988 666480259 747042520 231541618 643931761 30317274 158530414 253502390 229547045 438239031 709645547 367432988 755781758 67144518 360508870 862615691 635226301 863755466 104979114 4...
output:
4698977666
result:
wrong answer 1st lines differ - expected: '5115514604', found: '4698977666'