QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#408939 | #6539. Treasure Box | Doqe | WA | 9ms | 9724kb | C++17 | 1.2kb | 2024-05-11 12:20:40 | 2024-05-11 12:20:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int nd[N],V[N];
long long val[N];
char s[N];
int main()
{
int T;cin>>T;
while(T--)
{
int n,C,pl=0,pr=0;
cin>>n>>C>>s+1;
for(int i=1;i<=n;++i)cin>>V[i];
for(int i=1;i<=n;++i)nd[i]=s[i]!=s[n-i+1],val[i]=1e18;
for(int i=1;i<=n;++i)if(nd[i])pr=i;
if(!pr){for(int i=1;i<=n;++i)cout<<"0 ";cout<<"\n";continue;}
pl=n-pr+1;
{
long long mn=0,t;int z=-1;
for(int i=pr;i>n/2;--i)if(nd[i])mn+=V[i],z=i;
assert(z!=-1);
val[pr]=1ll*(pr-z)*C+mn;
for(int i=z-1;i>pl;--i)
{
if(nd[i])mn-=V[n-i+1]-min(V[i],V[n-i+1]),
val[pr]=min(val[pr],1ll*(pr-i)*C+mn);
val[i]=1ll*(pr-i)*C+mn;
}
}
{
long long mn=0;int z=-1;
for(int i=pl;i<=n/2;++i)if(nd[i])mn+=V[i],z=i;
assert(z!=-1);
val[pl]=1ll*(z-pl)*C+mn;
for(int i=z+1;i<pr;++i)
{
if(nd[i])mn-=V[n-i+1]-min(V[i],V[n-i+1]),
val[pr]=min(val[pr],1ll*(i-pl)*C+mn);
val[i]=1ll*(i-pl)*C+mn;
}
}
// for(int i=1;i<=n;++i)cout<<val[i]<<' ';cout<<"\n";
for(int i=2;i<=n;++i)val[i]=min(val[i],val[i-1]+C);
for(int i=n-1;i;--i)val[i]=min(val[i],val[i+1]+C);
for(int i=1;i<=n;++i)cout<<val[i]<<' ';cout<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9724kb
input:
2 5 1 ABCDE 7 1 4 5 1 5 1 ABCDA 7 1 4 5 1
output:
6 5 6 6 5 2 1 2 3 4
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 7744kb
input:
1 10 4 AABABBABAB 10 3 4 10 7 1 8 10 7 6
output:
10 14 18 22 26 22 18 14 10 6
result:
ok 10 numbers
Test #3:
score: -100
Wrong Answer
time: 9ms
memory: 9640kb
input:
10000 10 4 ABBBAABABB 6 10 3 9 1 8 5 4 4 10 10 4 BABBAAABAB 3 7 5 9 2 3 9 8 4 1 10 4 ABBBAAABAA 3 2 4 8 2 9 1 9 6 3 10 4 BBAABBAABB 8 8 10 7 1 1 4 9 6 4 10 4 BAABBBBBAB 5 7 3 5 4 2 1 8 2 8 10 4 ABAAAABABA 10 8 2 7 5 3 7 8 10 5 10 4 BBABABAABA 10 6 10 2 2 6 4 4 3 9 10 4 BBBAAAABBB 7 2 2 8 9 10 10 6 7...
output:
17 21 25 21 25 29 33 30 26 22 21 17 13 9 13 13 9 13 17 21 22 18 22 26 22 26 23 19 15 19 0 0 0 0 0 0 0 0 0 0 11 7 3 7 11 15 12 8 12 16 19 15 11 7 11 11 7 11 15 19 30 34 38 37 35 34 38 42 38 34 0 0 0 0 0 0 0 0 0 0 11 7 3 7 11 13 9 5 9 13 8 4 8 12 16 14 10 6 2 6 18 14 10 6 10 14 10 14 18 22 ...
result:
wrong answer 3rd numbers differ - expected: '17', found: '25'