QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368524 | #7988. 史莱姆工厂 | rageOfThunder# | TL | 2ms | 14040kb | C++14 | 2.3kb | 2024-03-27 11:00:56 | 2024-03-27 11:00:58 |
Judging History
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));
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("hack.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: 100
Accepted
time: 2ms
memory: 12084kb
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: 14040kb
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 ...