Submission #1026932
Source Code Expand
#define DEB #include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl #define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define dumpR(x) ; #define dumpY(x) ; #define dumpG(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } const lint INF=1e18; int n; pi range[5005]; lint dp[5005][5005]; int main(){ cin>>n; REP(i,n) cin>>range[i].fr>>range[i].sc; sort(range,range+n,[&](pi a,pi b ){ return a.fr+a.sc>b.fr+b.sc; }); REP(i,5005) REP(j,5005) dp[i][j]=INF; int m=(n+1)/2; dp[0][0]=0; REP(i,m+1) REP(j,m+1) if(dp[i][j]<INF){ pi r=range[i+j]; lint sum=r.fr+r.sc; if(n&1 && i+1==m) chmin(dp[i+1][j],dp[i][j]+sum*i); else chmin(dp[i+1][j],dp[i][j]+sum*i+r.sc); if(n&1 && j+1==m) chmin(dp[i][j+1],dp[i][j]+sum*j); else chmin(dp[i][j+1],dp[i][j]+sum*j+r.fr); } lint res=INF; REP(i,m+1) REP(j,m+1) if(i+j==n) chmin(res,dp[i][j]); cout<<res<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Intervals |
User | hogloid |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1946 Byte |
Status | AC |
Exec Time | 229 ms |
Memory | 195968 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 227 ms | 195968 KB |
001.txt | AC | 202 ms | 195968 KB |
002.txt | AC | 226 ms | 195968 KB |
003.txt | AC | 221 ms | 195968 KB |
004.txt | AC | 226 ms | 195968 KB |
005.txt | AC | 208 ms | 195968 KB |
006.txt | AC | 227 ms | 195968 KB |
007.txt | AC | 212 ms | 195968 KB |
008.txt | AC | 226 ms | 195968 KB |
009.txt | AC | 198 ms | 195968 KB |
010.txt | AC | 226 ms | 195968 KB |
011.txt | AC | 210 ms | 195968 KB |
012.txt | AC | 226 ms | 195968 KB |
013.txt | AC | 198 ms | 195968 KB |
014.txt | AC | 227 ms | 195968 KB |
015.txt | AC | 202 ms | 195968 KB |
016.txt | AC | 228 ms | 195968 KB |
017.txt | AC | 219 ms | 195968 KB |
018.txt | AC | 226 ms | 195968 KB |
019.txt | AC | 211 ms | 195968 KB |
020.txt | AC | 195 ms | 195968 KB |
021.txt | AC | 196 ms | 195968 KB |
022.txt | AC | 228 ms | 195968 KB |
023.txt | AC | 226 ms | 195968 KB |
024.txt | AC | 228 ms | 195968 KB |
025.txt | AC | 226 ms | 195968 KB |
026.txt | AC | 228 ms | 195968 KB |
027.txt | AC | 226 ms | 195968 KB |
028.txt | AC | 229 ms | 195968 KB |
029.txt | AC | 226 ms | 195968 KB |
030.txt | AC | 228 ms | 195968 KB |
031.txt | AC | 226 ms | 195968 KB |
032.txt | AC | 228 ms | 195968 KB |
033.txt | AC | 227 ms | 195968 KB |
034.txt | AC | 227 ms | 195968 KB |
035.txt | AC | 226 ms | 195968 KB |
036.txt | AC | 228 ms | 195968 KB |
037.txt | AC | 227 ms | 195968 KB |
038.txt | AC | 229 ms | 195968 KB |
039.txt | AC | 227 ms | 195968 KB |
040.txt | AC | 229 ms | 195968 KB |
041.txt | AC | 226 ms | 195968 KB |
042.txt | AC | 227 ms | 195968 KB |
example0.txt | AC | 195 ms | 195968 KB |
example1.txt | AC | 195 ms | 195968 KB |