QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302125 | #7988. 史莱姆工厂 | PhantomThreshold# | WA | 11ms | 6776kb | C++20 | 2.5kb | 2024-01-10 16:39:11 | 2024-01-10 16:39:11 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
inline void up(int &a,const int &b){ if(a<b)a=b; }
const int maxn = 200;
const int maxk = 12;
const int inf = 1e15;
int n,K,W;
int ci[maxn],mi[maxn];
int pi[maxn];
int f[maxn][maxn][maxk],g[maxn][maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin>>n>>K>>W;
for(int i=1;i<=n;i++) cin>>ci[i];
for(int i=1;i<=n;i++) cin>>mi[i];
for(int i=K;i<=2*K-2;i++) cin>>pi[i];
if(n<=10)
{
auto elim=[&](vector<pair<int,int>>& now)
{
int ok=0,sum=0;
while(not ok)
{
ok=1;
for(int i=0;i<(int)now.size();i++)
{
if(now[i].second>=K)
{
sum+=pi[now[i].second];
now.erase(now.begin()+i);
ok=0;
break;
}
if(i+1<(int)now.size() and now[i].first==now[i+1].first)
{
now[i].second+=now[i+1].second;
now.erase(now.begin()+i+1);
ok=0;
break;
}
}
}
return sum;
};
long long ans=-inf;
function<void(vector<pair<int,int>>,int)> dfs=[&](vector<pair<int,int>> now,int cost)
{
if(now.empty())
{
ans=max(ans,cost);
return;
}
for(int i=0;i<(int)now.size();i++)
{
auto tmp=now;
int tw=K-tmp[i].second;
tmp[i].second=K;
int del=elim(tmp);
dfs(tmp,cost+del-tw*W);
}
};
vector<pair<int,int>> a;
for(int i=1;i<=n;i++)a.emplace_back(ci[i],mi[i]);
dfs(a,0);
cout<<ans<<endl;
return 0;
}
for(int i=1;i<=n;i++)
{
for(int k=0;k<=K;k++) f[i][i][k]=-inf;
f[i][i][mi[i]]=0;
g[i][i]= pi[K]-W*(K-mi[i]);
}
for(int L=2;L<=n;L++)
{
for(int r=L;r<=n;r++)
{
int l= r-L+1;
g[l][r]=-inf;
for(int k=0;k<=K;k++) f[l][r][k]=-inf;
for(int mid=l+1;mid<=r;mid++)
{
//f+f
if(ci[l]==ci[mid])
{
for(int x=1;x<K;x++) for(int y=1;y<K;y++)
{
if(x+y>=K)
{
up(g[l][r],f[l][mid-1][x]+f[mid][r][y]+pi[x+y]);
}
else
{
up(f[l][r][x+y],f[l][mid-1][x]+f[mid][r][y]);
}
}
}
//f+g
for(int x=1;x<K;x++) up(f[l][r][x],f[l][mid-1][x]+g[mid][r]);
//g+f
//for(int y=1;y<K;y++) up(f[l][r][y],g[l][mid-1]+f[mid][r][y]);
//g+g
up(g[l][r],g[l][mid-1]+g[mid][r]);
}
// if( r!=n&&ci[l]==ci[r+1] )
// {
// for(int k=1;k<K;k++) f[l][r][k]=-inf;
// }
if(r==n||ci[l]!=ci[r+1])
{
for(int k=1;k<K;k++) up(g[l][r],f[l][r][k]+pi[K]-W*(K-k));
}
// if( l!=1&&r!=n&&ci[l-1]==ci[r+1] ) g[l][r]=-inf;
}
}
cout<<g[1][n]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 3776kb
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: 0
Accepted
time: 11ms
memory: 6776kb
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:
392867316
result:
ok single line: '392867316'
Test #4:
score: -100
Wrong Answer
time: 9ms
memory: 6168kb
input:
150 10 10105 8 6 8 6 8 3 8 5 8 5 1 5 1 5 6 5 6 5 6 7 6 5 6 1 6 4 6 4 3 4 9 4 1 4 1 4 1 5 1 9 1 4 1 9 1 9 3 9 1 9 5 9 8 9 8 5 8 7 8 4 8 6 8 6 2 6 9 6 4 6 5 6 5 3 5 1 5 4 5 8 5 8 9 8 7 8 6 8 1 8 1 8 1 8 1 6 1 7 1 7 2 7 4 7 6 7 4 7 4 5 4 7 4 7 4 3 4 3 7 3 2 3 8 3 4 3 4 8 4 7 4 9 4 2 4 2 7 2 8 2 7 2 9 2...
output:
9264040
result:
wrong answer 1st lines differ - expected: '9262990', found: '9264040'