QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#534823#7988. 史莱姆工厂Ecrade_WA 32ms115056kbC++143.5kb2024-08-27 16:33:252024-08-27 16:33:26

Judging History

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

  • [2024-08-27 16:33:26]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:115056kb
  • [2024-08-27 16:33:25]
  • 提交

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],hh[159][159][159][3];
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 = i;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 k = 1;k <= n;k += 1) for (ll l = 0;l < 3;l += 1) hh[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;
                for (ll k = 1;k <= n;k += 1){
                    if (k == c[i]) continue;
                    hh[i][j][k][0] = f[i][j];
                }
				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){
					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 == 1 && j == 3) 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 + 1]){
                        for (ll o = i;o < j;o += 1){
                            if (c[o] != c[i]) continue;
                            chkmax(g[i][j][k][l],g[i][o][k][l] + hh[o + 1][j][c[i]][0]);
                            chkmax(g[i][j][k][l],g[i][o][k][l] + hh[o + 1][j][c[i]][2]);
						    //if (i == 1 && j == 2) cout<<k<<' '<<l<<' '<<o<<' '<<g[i][j][k][l]<<"WTF"<<endl;
                        }
                    }
				}
			}
            for (ll k = i;k <= j;k += 1){
                if (c[k] != c[j]) continue;
                for (ll l = 1;l <= n;l += 1){
                    if (c[i] == l) continue;
                    if (c[j] != l && c[j] != c[i]){
                        chkmax(hh[i][j][l][2],max({hh[i][k - 1][l][0],hh[i][k - 1][l][1],hh[i][k - 1][l][2]}) + f[k][j]);
                    }
                    else if (c[j] == l){
                        chkmax(hh[i][j][l][1],max({hh[i][k - 1][l][0],hh[i][k - 1][l][1]}) + f[k][j]);
                        chkmax(hh[i][j][l][2],hh[i][k - 1][l][2] + f[k][j]);
                    }
                    else{
                        chkmax(hh[i][j][l][0],hh[i][k - 1][l][0] + f[k][j]);
                        chkmax(hh[i][j][l][1],hh[i][k - 1][l][1] + f[k][j]);
                        chkmax(hh[i][j][l][2],hh[i][k - 1][l][2] + f[k][j]);
                    }
                }
            }
			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: 11992kb

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: 1ms
memory: 12060kb

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: 26ms
memory: 111396kb

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: 0
Accepted
time: 28ms
memory: 115056kb

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:

9262990

result:

ok single line: '9262990'

Test #5:

score: -100
Wrong Answer
time: 32ms
memory: 114708kb

input:

150 10 491282
5 7 1 4 5 3 5 3 5 6 7 3 6 3 4 5 4 2 3 7 3 4 7 2 3 7 5 4 6 1 7 5 2 6 4 1 6 2 5 4 1 3 6 7 5 6 2 1 3 2 1 7 1 2 6 1 2 6 4 3 7 6 5 3 5 4 1 2 7 1 5 6 2 6 5 1 3 5 6 3 4 5 1 3 7 4 6 4 2 6 3 7 5 7 1 2 7 4 3 2 1 4 2 7 4 6 2 3 6 4 7 1 5 3 2 1 3 4 3 6 7 3 7 5 6 2 4 2 1 3 2 3 7 5 3 5 6 4 6 1 2 6 7 ...

output:

297591526

result:

wrong answer 1st lines differ - expected: '300542698', found: '297591526'