QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368515#7988. 史莱姆工厂rageOfThunder#WA 2ms11924kbC++142.3kb2024-03-27 10:50:282024-03-27 10:50:29

Judging History

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

  • [2024-03-27 10:50:29]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11924kb
  • [2024-03-27 10:50:28]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define mk make_pair
#define fi first
#define se second

using namespace std;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
	for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
	return x*f;
}

const int mod=998244353;
int ksm(int x,ll y,int p=mod){
	int ans=1;y%=(p-1);
	for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
	return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}

template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}

const int N=152;
const int K=19;

ll f[N][N],g[N][N][K][N];
bool vf[N][N],vg[N][N][K][N];
int p[K],col[N],sz[N],n,k,w;

const ll INF=1e18;
ll F(int l,int r);
ll G(int l,int r,int s,int x);

string pr(ll x){
	if(x<=-100000000000000)return "-";
	return to_string(x);
}

//vector<int>vals[N];
ll F(int l,int r){
	if(l>r)return 0ll;
	if(vf[l][r])return f[l][r];
	ll ans=-INF;vf[l][r]=true;
	for(int s=1;s<=2*k-2;s++)for(int x=1;x<=n;x++)if(x!=col[l-1]&&x!=col[r+1]){
		ll now=G(l,r,s,x);now+=p[max(k,s)];
		if(s<k)now-=1ll*(k-s)*w;
		cmax(ans,now);
//		cout<<"now f ["<<l<<","<<r<<"] = "<<pr(ans)<<endl;
	}
//	cout<<"f ["<<l<<","<<r<<"] = "<<pr(ans)<<endl;
	return f[l][r]=ans;
}
ll G(int l,int r,int s,int x){
	if(s==0)return F(l,r);
	if(l>r)return -INF;
	if(x==col[l-1]||x==col[r+1])return -INF;
	if(vg[l][r][s][x])return g[l][r][s][x];
	ll ans=-INF;vg[l][r][s][x]=true;
	for(int p=l;p<=r;p++)if(col[p]==x){
		if(sz[p]==s)cmax(ans,F(l,p-1)+F(p+1,r));
		if(l<p&&p<=r){
			for(int q=p+1;q<=r;q++)if(col[q]==x){
				for(int y=1;y<=min(s-1,k-1);y++)if(s-y<=k-1)cmax(ans,G(l,p,y,x)+F(p+1,q-1)+G(q,r,s-y,x));
			}
		}
	}
//	cout<<"g ["<<l<<","<<r<<"]sum = "<<s<<" col = "<<x<<" res = "<<pr(ans)<<endl;
	return g[l][r][s][x]=ans;
}

signed main(void){

#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif

	n=read(),k=read(),w=read();
	for(int i=1;i<=n;i++)col[i]=read();
	for(int i=1;i<=n;i++)sz[i]=read();
	for(int i=k;i<=2*k-2;i++)p[i]=read();
	
	cout<<F(1,n)<<endl;

	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 11924kb

input:

4 5 6
2 1 2 3
3 3 3 4
5 7 9 11

output:

-22

result:

wrong answer 1st lines differ - expected: '-1', found: '-22'