Submission #61507

# Submission time Handle Problem Language Result Execution time Memory
61507 2018-07-26T06:09:10 Z 윤교준(#1780) Homecoming (BOI18_homecoming) C++11
31 / 100
1000 ms 16272 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];
		
		deque<pil> PQ;
		ll mx1 = -INFLL;
		for(int i = 0; i < N-K; i++) {
			if(0 <= i-K) upmax(mx1, dp[i-K]);
			for(; !PQ.empty() && PQ[0].first < max(0, i-K+1); PQ.pop_front());
			ll &ret = dp[i];
			ret = ll(A[i]) - S[i+K] + S[i];
			if(!PQ.empty()) upmax(ret, PQ[0].second + A[i] - S[i+K]);
			upmax(ret, mx1 + A[i] - S[i+K] + S[i]);

			ll t = ret + S[i+K];
			for(; !PQ.empty() && PQ.back().second <= t; PQ.pop_back());
			PQ.pb(pil(i, t));

			upmax(Ans, ret);
		}
	}

	return Ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 536 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 536 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
6 Correct 86 ms 660 KB Output is correct
7 Correct 189 ms 808 KB Output is correct
8 Correct 73 ms 808 KB Output is correct
9 Correct 495 ms 808 KB Output is correct
10 Correct 7 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 16272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 7 ms 536 KB Output is correct
5 Correct 4 ms 536 KB Output is correct
6 Correct 86 ms 660 KB Output is correct
7 Correct 189 ms 808 KB Output is correct
8 Correct 73 ms 808 KB Output is correct
9 Correct 495 ms 808 KB Output is correct
10 Correct 7 ms 808 KB Output is correct
11 Execution timed out 1069 ms 16272 KB Time limit exceeded
12 Halted 0 ms 0 KB -