이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int N;
int h[100100], w[100100];
int m[1001][1000];
int solve(int n, int ln){
if(n==0){
///first node
return solve(n+1, n);
}
else if(n==N-1){
//last node
return abs(h[n]-h[ln])*abs(h[n]-h[ln]);
}
if(m[n][ln]!=-1)
return m[n][ln];
return m[n][ln] = min(solve(n+1, n)+(abs(h[n]-h[ln])*abs(h[n]-h[ln])), solve(n+1, ln)+w[n]);
}
int main(){
cin>>N;
memset(m, -1, sizeof(m));
for(int n=0; n<N; n++){
cin>>h[n];
}
for(int n=0; n<N; n++)
cin>>w[n];
vector<int> m(N+1, -1);
priority_queue<pair<int, int> > q; q.push({0, N-1});
for(int n=N-2; n>=1; n--){
while(!q.empty()){
pair<int, int> t = q.top(); q.pop();
t.first = -t.first;
}
}
cout << solve(0, 0) << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |