QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408938#6539. Treasure BoxDoqeWA 1ms7696kbC++171.2kb2024-05-11 12:18:562024-05-11 12:18:58

Judging History

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

  • [2024-05-11 12:18:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7696kb
  • [2024-05-11 12:18:56]
  • 提交

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'