QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368535#7988. 史莱姆工厂Naganohara_YoimiyaTL 0ms16956kbC++142.6kb2024-03-27 11:37:262024-03-27 11:37:26

Judging History

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

  • [2024-03-27 11:37:26]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:16956kb
  • [2024-03-27 11:37:26]
  • 提交

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);
}

set<int>cols[N][N];
//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:cols[l][r])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;
}
vector<int>pos[N];
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;
	int st=lower_bound(pos[x].begin(),pos[x].end(),l)-pos[x].begin();
	for(int i=st;i<pos[x].size()&&pos[x][i]<=r;i++){
		int p=pos[x][i];
		if(sz[p]==s)cmax(ans,F(l,p-1)+F(p+1,r));
		for(int j=i+1;j<pos[x].size()&&pos[x][j]<=r;j++){
			int q=pos[x][j];
			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("hack3.in","r",stdin);
#endif

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

	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13064kb

input:

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

output:

-1

result:

ok single line: '-1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 16956kb

input:

5 7 500
2 3 2 3 2
5 6 6 6 4
1000 900 800 400 200 50

output:

1400

result:

ok single line: '1400'

Test #3:

score: -100
Time Limit Exceeded

input:

150 10 465782
6 1 4 3 2 6 1 3 5 3 4 6 1 2 1 5 1 6 2 1 5 4 6 1 3 2 6 5 4 3 1 6 3 4 1 4 1 6 3 6 1 4 2 4 6 4 3 1 5 6 4 2 1 4 6 2 5 1 3 1 4 6 5 6 3 2 3 4 2 3 6 3 5 2 6 1 5 4 5 2 4 1 4 3 4 1 3 2 6 1 4 5 4 6 2 1 3 1 2 1 3 5 2 3 2 6 5 3 1 4 1 5 1 6 2 5 4 2 4 1 4 2 5 6 4 3 5 1 3 2 5 4 6 4 3 5 3 4 5 3 2 1 4 ...

output:


result: