Submission #61459

# Submission time Handle Problem Language Result Execution time Memory
61459 2018-07-26T04:40:18 Z 윤교준(#1780) Homecoming (BOI18_homecoming) C++11
13 / 100
1000 ms 12748 KB
#include "homecoming.h"
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define sz(V) ((int)(V).size())
#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;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

const int MAXN = 2000005;

ll dp[MAXN], S[MAXN];
int A[MAXN], B[MAXN];

ll Ans;
int N, K;

void init() {
	Ans = 0;
}

ll solve(int _N, int _K, int *_A, int *_B) {
	init();
	N = _N; K = _K;
	for(int i = 0; i < N; i++) {
		A[i] = _A[i];
		B[i] = _B[i];
	}

	{
		ll sum = 0;
		for(int i = 0; i < N; i++)
			sum += ll(A[i]) - B[i];
		upmax(Ans, sum);
	}

	for(int ti = 0; ti < N; ti++) {
		rotate(A, A+1, A+N);
		rotate(B, B+1, B+N);

		S[0] = 0;
		for(int i = 1; i <= N; i++)
			S[i] = S[i-1] + B[i-1];
		
		for(int i = 0; i < N-K; i++) {
			ll &ret = dp[i];
			ret = ll(A[i]) - S[i+K] + S[i];
			for(int j = max(0, i-K+1); j < i; j++)
				upmax(ret, dp[j] + A[i] - S[i+K] + S[j+K]);
			for(int j = 0; j <= i-K; j++)
				upmax(ret, dp[j] + A[i] - S[i+K] + S[i]);

			upmax(Ans, ret);
		}
	}

	return Ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 104 ms 520 KB Output is correct
5 Correct 3 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 104 ms 520 KB Output is correct
5 Correct 3 ms 520 KB Output is correct
6 Correct 84 ms 660 KB Output is correct
7 Execution timed out 1049 ms 764 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 12748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 104 ms 520 KB Output is correct
5 Correct 3 ms 520 KB Output is correct
6 Correct 84 ms 660 KB Output is correct
7 Execution timed out 1049 ms 764 KB Time limit exceeded
8 Halted 0 ms 0 KB -