답안 #673410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673410 2022-12-20T14:34:02 Z vjudge1 Cover (COCI18_cover) C++14
120 / 120
3 ms 468 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back

const int N = 5005;

int n;
ll dp[N];
map<int,int> mp;
vector<pii> myVec;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1, x, y; i <= n; i++) {
    	cin >> x >> y;
    	x = abs(x), y = abs(y);
    	auto it = mp.find(x);
    	if (it == mp.end()) mp[x] = y;
    	else mp[x] = max(y, it->se);
    }
    for (auto it : mp) {
    	while (!myVec.empty() && it.se >= myVec.back().se)
    		myVec.pop_back();
    	myVec.pb(it);
    }
    n = myVec.size();
    for (int i = 0; i < n; i++) {
    	dp[i] = 4 * myVec[i].fi * myVec[0].se;
    	for (int j = 0; j < i; j++)
    		dp[i] = min(dp[i], dp[j] + 4 * myVec[i].fi * myVec[j + 1].se);
    }
    cout << dp[n - 1];
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 468 KB Output is correct