QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368490 | #7988. 史莱姆工厂 | rageOfThunder# | WA | 2ms | 16116kb | C++14 | 2.1kb | 2024-03-27 09:53:02 | 2024-03-27 09:53:03 |
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);
}
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++){
ll now=G(l,r,s,x);now+=p[max(k,s)];
if(s<k)now-=1ll*(k-s)*w;
cmax(ans,now);
}
// cout<<"f ["<<l<<","<<r<<"] = "<<f[l][r]<<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(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 y=0;y<=min(s,k-1);y++)if(s-y<=k-1)cmax(ans,G(l,p-1,y,x)+G(p,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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11976kb
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: -100
Wrong Answer
time: 2ms
memory: 16116kb
input:
5 7 500 2 3 2 3 2 5 6 6 6 4 1000 900 800 400 200 50
output:
2300
result:
wrong answer 1st lines differ - expected: '1400', found: '2300'