이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include "holiday.h"
#define int long long
using namespace std;
vector<vector<int>> dprr;
vector<vector<int>> dplr;
vector<vector<int>> dprs;
vector<vector<int>> dpls;
vector<int> gattraction;
int gn;
int maxrightret(int i, int j){
if(j <=0 || i == gn) return 0;
if(dprr[i][j] != -1) return dprr[i][j];
int best = maxrightret(i+1, j-2);
if(j >= 1) best = max(best, maxrightret(i+1, j-3)+gattraction[i]);
return dprr[i][j] = best;
}
int maxrightsta(int i, int j){
if(j <=0 || i == gn) return 0;
if(dprs[i][j] != -1) return dprs[i][j];
int best = maxrightsta(i+1, j-1);
if(j >= 1) best = max(best, maxrightsta(i+1, j-2)+gattraction[i]);
return dprs[i][j] = best;
}
int maxleftret(int i, int j){
if(j <= 0 || i == -1) return 0;
if(dplr[i][j] != -1) return dplr[i][j];
int best = maxleftret(i-1, j-2);
if(j >= 1) best = max(best, maxleftret(i-1, j-3)+gattraction[i]);
return dplr[i][j] = best;
}
int maxleftsta(int i, int j){
if(j <= 0 || i == -1) return 0;
if(dpls[i][j] != -1) return dpls[i][j];
int best = maxleftsta(i-1, j-1);
if(j >= 1) best = max(best, maxleftsta(i-1, j-2)+gattraction[i]);
return dpls[i][j] = best;
}
int findMaxAttraction(signed n, signed start, signed d, signed attraction[]){
gattraction = vector<int> (n);
for(int attracter = 0; attracter < n; attracter++) gattraction[attracter] = attraction[attracter];
dprr = vector<vector<int>> (n, vector<int> (d+1, -1));
dplr = vector<vector<int>> (n, vector<int> (d+1, -1));
dprs = vector<vector<int>> (n, vector<int> (d+1, -1));
dpls = vector<vector<int>> (n, vector<int> (d+1, -1));
gn = n;
int best = 0;
for(int left = 0; left <= d; left++){
best = max(best, maxleftret(start-1,left - 2) + maxrightsta(start+1, d-left-1));
if(left > 0) best = max(best, maxleftret(start-1,left - 3) + maxrightsta(start+1, d-left-1) + attraction[start]);
}
for(int right = 0; right <= d; right++){
best = max(best, maxleftsta(start-1, d-right-1) + maxrightret(start+1, right-2));
if(right > 0) best = max(best, maxleftsta(start-1,d-right-1) + maxrightret(start+1, right-3) + attraction[start]);
}
return best;
}
/*signed main(){
int n, start, d; cin >> n >> start >> d;
signed *attraction = new signed[n];
for(int reader = 0; reader < n; reader++) cin >> attraction[reader];
cout << findMaxAttraction(n,start,d,attraction);
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |