답안 #147245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147245 2019-08-28T13:45:26 Z SeekingOblivion Cover (COCI18_cover) C++14
120 / 120
11 ms 504 KB
//#include<fstream>
#include<queue>
#include<algorithm>
#include<iostream>
#define fin cin
#define fout cout
using namespace std;
//ifstream fin("date.in");
//ofstream fout("date.out");
int i,a,b,n,m,j;
long long sol[5010];
pair<int,int> v[5010],d[5010];
int main()
{
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>a>>b;
        if(a<0) a=-a;
        if(b<0) b=-b;
        v[i].first=a;v[i].second=b;
    }
    sort(v+1,v+n+1);
    for(i=1;i<=n;i++)
    {
        while(m>0&&d[m].second<v[i].second) m--;
        d[++m]=v[i];
    }
    for(i=1;i<=m;i++) sol[i]=9223372036854775807;
    for(i=1;i<=m;i++)
        for(j=i;j>=1;j--)
            sol[i]=min(sol[j-1]+1LL*d[i].first*d[j].second,sol[i]);
    fout<<sol[m]*4;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 248 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 11 ms 476 KB Output is correct