QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534627 | #7988. 史莱姆工厂 | Ecrade_ | WA | 0ms | 3908kb | C++14 | 2.0kb | 2024-08-27 14:34:19 | 2024-08-27 14:34:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,w,p[20],a[159],c[159],f[159][159],g[159][159][10][10],h[159];
inline ll read(){
ll s = 0,w = 1;
char ch = getchar();
while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();}
while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
return s * w;
}
inline void chkmax(ll &x,ll y){if (x < y) x = y;}
int main(){
n = read(),m = read(),w = read();
for (ll i = 1;i <= n;i += 1) c[i] = read();
for (ll i = 1;i <= n;i += 1) a[i] = read();
for (ll i = m;i <= 2 * m - 2;i += 1) p[i] = read();
for (ll i = 1;i <= n;i += 1) for (ll j = 1;j <= n;j += 1){
f[i][j] = -1e18;
for (ll k = 0;k < m;k += 1) for (ll l = 0;l < m;l += 1) g[i][j][k][l] = -1e18;
}
for (ll i = n;i >= 1;i -= 1){
ll cnt = 0;
for (ll j = i;j <= n;j += 1){
cnt += (c[i] == c[j]) * a[j];
if (i == j){
f[i][j] = p[m] - w * (m - a[i]);
g[i][j][a[i]][0] = 0;
continue;
}
ll res = -1e18;
for (ll k = 0;k <= min(m - 1,cnt);k += 1){
for (ll l = 0;l <= m - 1 && k + l <= cnt;l += 1){
for (ll o = i;o < j;o += 1){
chkmax(g[i][j][k][l],g[i][o][k][l] + f[o + 1][j]);
// if (i == 1 && j == 2) cout<<k<<' '<<l<<' '<<o<<' '<<g[i][j][k][l]<<"WTF"<<endl;
}
if (c[i] == c[j]){
if (k >= a[j] && !l) chkmax(g[i][j][k][l],g[i][j - 1][k - a[j]][l]);
if (l >= a[j]) chkmax(g[i][j][k][l],g[i][j - 1][k][l - a[j]]);
// if (i == 2 && j == 4) cout<<k<<' '<<l<<' '<<g[i][j][k][l]<<"HHH"<<endl;
if (k + l < m) chkmax(res,g[i][j][k][l] + p[m] - w * (m - k - l));
else chkmax(res,g[i][j][k][l] + p[k + l]);
}
}
}
if (c[i] == c[j]) f[i][j] = res;
}
}
// for (ll i = 1;i <= n;i += 1) for (ll j = i;j <= n;j += 1) cout<<i<<'.'<<j<<' '<<f[i][j]<<endl;
for (ll i = 1;i <= n;i += 1){
h[i] = -1e18;
for (ll j = 1;j <= i;j += 1) chkmax(h[i],h[j - 1] + f[j][i]);
}
printf("%lld",h[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 0ms
memory: 3908kb
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'