# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
796498 | vjudge1 | Cover (COCI18_cover) | C++17 | 25 ms | 524 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
//#define ld long double
using namespace std;
using ll=long long;
const int inf = 2e18;
const int MN = 5e3+5;
const int mod=998244353;
int n;
pii a[MN];
int dp[MN];
inline void solve() {
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i].fi>>a[i].se;
a[i].fi=abs(a[i].fi);
a[i].se=abs(a[i].se);
}
sort(a+1,a+n+1);
// build(1,1,n);
for (int i=1; i<=n; i++) dp[i]=inf;
for (int i=1; i<=n; i++) {
int mx=-inf, mn=inf;
for (int j=i; j>=1; j--) {
mx=max(mx,a[j].se);
mn=min(mn,a[j].se);
dp[i]=min(dp[i],dp[j-1]+a[i].fi*2*mx*2);
}
}
cout<<dp[n];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// preprocess();
// cin>>t;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |