답안 #73787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73787 2018-08-29T03:45:18 Z 윤교준(#2277) 놀이터에 떨어진 이상한 약 (FXCUP3_gorgeous) C++11
51 / 100
39 ms 17416 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1005;

ll dp[MAXN][MAXN];
bitset<MAXN> chk[MAXN];

int A[MAXN], B[MAXN];

int N;

ll f(int s, int e) {
	if(1 == s && e == N) return 0;
	if(chk[s][e]) return dp[s][e];
	chk[s][e] = true;
	ll &ret = dp[s][e];
	int l = e-s+2;

	if(1 < s) upmax(ret, f(s-1, e) + (A[s-1] == l ? B[s-1] : 0));
	if(e < N) upmax(ret, f(s, e+1) + (A[e+1] == l ? B[e+1] : 0));
	return ret;
}

int main() {
	ios::sync_with_stdio(false);

	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 = 1; i <= N; i++)
		printf("%lld ", f(i, i) + (1 == A[i] ? B[i] : 0));
	puts("");
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 488 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 4 ms 904 KB Output is correct
9 Correct 3 ms 1064 KB Output is correct
10 Correct 6 ms 2568 KB Output is correct
11 Correct 14 ms 5768 KB Output is correct
12 Correct 21 ms 7320 KB Output is correct
13 Correct 19 ms 7680 KB Output is correct
14 Correct 20 ms 7680 KB Output is correct
15 Correct 20 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 488 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 4 ms 904 KB Output is correct
9 Correct 3 ms 1064 KB Output is correct
10 Correct 6 ms 2568 KB Output is correct
11 Correct 14 ms 5768 KB Output is correct
12 Correct 21 ms 7320 KB Output is correct
13 Correct 19 ms 7680 KB Output is correct
14 Correct 20 ms 7680 KB Output is correct
15 Correct 20 ms 7680 KB Output is correct
16 Runtime error 39 ms 17416 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Halted 0 ms 0 KB -