답안 #217340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217340 2020-03-29T12:45:17 Z vanic Cover (COCI18_cover) C++14
120 / 120
12 ms 768 KB
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
/*
#include <dora>
#include <vito>
*/
#include <string>
#include <map>
#include <queue>
//#include <>
using namespace std;
typedef long long ll;

const int maxn=5005;
const ll inf=1e18;

int n;
map < pair < int, int >, bool > bio;
vector < pair < int, int > > v;
deque < pair < int, int > > q;
ll dp[maxn];


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	pair < int, int > p;
	for(int i=0; i<n; i++){
		cin >> p.first >> p.second;
		p.first=abs(p.first);
		p.second=abs(p.second);
		if(!bio[p]){
			bio[p]=1;
			v.push_back(p);
		}
	}
	n=v.size();
	sort(v.begin(), v.end());
	for(int i=0; i<n; i++){
		while(!q.empty() && q.back().second<=v[i].second){
			q.pop_back();
		}
		q.push_back(v[i]);
	}
	v.clear();
	while(!q.empty()){
		v.push_back(q.front());
		q.pop_front();
	}
	n=v.size();
	for(int i=0; i<n; i++){
		dp[i]=inf;
		for(int j=0; j<=i; j++){
			if(j){
				dp[i]=min(dp[i], dp[j-1]+(ll)v[j].second*v[i].first);
			}
			else{
				dp[i]=min(dp[i], (ll)v[j].second*v[i].first);
			}
		}
	}
	cout << dp[n-1]*4 << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 392 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 12 ms 768 KB Output is correct