#include <bits/stdc++.h>
#define int unsigned long long
#define pb push_back
#define F first
#define S second
using namespace std;
typedef pair < int, int > ii;
const int maxn = 5e3+10, inf = 1e18;
int n, dp[maxn];
map < int, int > mapa;
int32_t main()
{
cin >> n;
for(int i = 1 ; i <= n ; i++)
{
int32_t xk, yk;
cin >> xk >> yk;
int x = (int)abs(xk+xk);
int y = (int)abs(yk+yk);
mapa[x] = max(mapa[x], y);
}
vector < ii > aux;
for(auto v : mapa)
{
if(!aux.size() or aux[aux.size()-1].S > v.S) aux.pb(v);
else if(aux.size())
{
aux.pop_back();
aux.pb(v);
}
}
//reverse(aux.begin(), aux.end());
/*for(int i = 0 ; i < aux.size() ; i++)
{
cout << aux[i].F << ' ' << aux[i].S << "\n";
}*/
dp[1] = 0;
for(int i = 1 ; i < aux.size() ; i++)
{
dp[i+1] = inf;
for(int j = 0 ; j < i ; j++)
{
dp[i+1] = min(dp[i+1], dp[j+1] + aux[j].S*aux[i-1].F);
}
}
int resp = inf;
for(int i = 0 ; i < aux.size() ; i++)
{
resp = min(resp, dp[i+1] + aux[i].S*aux[aux.size()-1].F);
}
cout << resp << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Incorrect |
9 ms |
504 KB |
Output isn't correct |
10 |
Incorrect |
12 ms |
632 KB |
Output isn't correct |