답안 #611903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
611903 2022-07-29T08:32:00 Z amunduzbaev Homecoming (BOI18_homecoming) C++17
0 / 100
1000 ms 24316 KB
#ifndef EVAL
#include "homecoming.h"
#endif
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

ll reshay(int n, int k, deque<int> a, deque<int> b){
	vector<ll> pa(n), pb(n), dp(n);
	for(int i=0;i<n;i++){
		pa[i] = a[i];
		if(i) pa[i] += pa[i-1];
		
		pb[i] = b[i];
		if(i) pb[i] += pb[i-1];
	}
	ll mx = 0, res = 0;
	for(int i=0;i<n;i++){
		if(i >= k) mx = max(mx, dp[i - k] - pa[i - k] + pb[i - k]);
		if(i + 1 >= k){
			dp[i] = mx - pb[i] + pa[i - k + 1];
		}
		res = max(res, dp[i]);
	}
	
	return res;
}

/*

1
3 2
40 80 100
140 0 20

*/

ll solve(int n, int k, int A[], int B[]){
	deque<int> a, b;
	ll res = 0;
	for(int i=0;i<n;i++) a.push_back(A[i]), res += A[i];
	for(int i=0;i<n;i++) b.push_back(B[i]), res -= B[i];
	res = max(res, 0ll);
	for(int i=0;i<n;i++){
		res = max(res, reshay(n, k, a, b));
		a.push_back(a.front()); a.pop_front();
		b.push_back(b.front()); b.pop_front();
	}
	
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 24316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -