Submission #73829

# Submission time Handle Problem Language Result Execution time Memory
73829 2018-08-29T05:37:33 Z 노영훈(#2275) Gorgeous Pill (FXCUP3_gorgeous) C++11
51 / 100
18 ms 8604 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=1010;
const ll linf=2e17;

int n, A[MX], B[MX];
ll D[MX][MX];

ll d(int a, int b){
	ll &res=D[a][b];
	if(res>=0) return res;
	res=0; int i = n - (a + n-b+1) + 1;
	if(1<=a) res=max(res, d(a-1,b)+(A[a]==i ? B[a] : 0));
	if(b<=n) res=max(res, d(a,b+1)+(A[b]==i ? B[b] : 0));
	return res;
}


int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=1; i<=n; i++) cin>>A[i];
	for(int i=1; i<=n; i++) cin>>B[i];

	for(int i=0; i<=n+1; i++) for(int j=0; j<=n+1; j++) D[i][j]=-1;
	D[0][n+1]=0;

	for(int i=1; i<=n; i++) cout<<d(i-1, i+1)+(A[i]==1 ? B[i] : 0)<<' ';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 932 KB Output is correct
9 Correct 3 ms 1060 KB Output is correct
10 Correct 5 ms 3108 KB Output is correct
11 Correct 10 ms 6692 KB Output is correct
12 Correct 14 ms 8104 KB Output is correct
13 Correct 18 ms 8544 KB Output is correct
14 Correct 15 ms 8544 KB Output is correct
15 Correct 18 ms 8604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 932 KB Output is correct
9 Correct 3 ms 1060 KB Output is correct
10 Correct 5 ms 3108 KB Output is correct
11 Correct 10 ms 6692 KB Output is correct
12 Correct 14 ms 8104 KB Output is correct
13 Correct 18 ms 8544 KB Output is correct
14 Correct 15 ms 8544 KB Output is correct
15 Correct 18 ms 8604 KB Output is correct
16 Runtime error 3 ms 8604 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Halted 0 ms 0 KB -