QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408938 | #6539. Treasure Box | Doqe | WA | 1ms | 7696kb | C++17 | 1.2kb | 2024-05-11 12:18:56 | 2024-05-11 12:18:58 |
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;
for(int i=pr;i>n/2;--i)if(nd[i])mn+=V[i],z=i;
val[pr]=1ll*(pr-z)*C+mn;
for(int i=z;i>pl;--i)
{
if(i!=z&&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;
for(int i=pl;i<=n/2;++i)if(nd[i])mn+=V[i],z=i;
val[pl]=1ll*(z-pl)*C+mn;
for(int i=z;i<pr;++i)
{
if(i!=z&&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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7696kb
input:
2 5 1 ABCDE 7 1 4 5 1 5 1 ABCDA 7 1 4 5 1
output:
9 8 7 6 5 2 1 2 3 4
result:
wrong answer 1st numbers differ - expected: '6', found: '9'