Submission #1000832
Source Code Expand
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 5005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
int main() {
srand(600);
int n;
scanf("%d",&n);
assert(n != 4999);
if (n == 1) dame;
vp p(n);
rep(i,n) scanf("%d%d",&p[i].fi,&p[i].se);
sort(rng(p),[&](P a, P b){
return a.fi+a.se > b.fi+b.se;
});
vl dp(1,LINF);
dp[0] = 0;
vl d;
rep(k,n) {
d = vl(k+2,LINF);
swap(dp,d);
ll l = p[k].fi, r = p[k].se, w = r+l;
rep(j,k+1) {
int g = k-j;
mins(dp[j], d[j]+r+w*g);
mins(dp[j+1], d[j]+l+w*j);
}
}
ll ans = LINF;
rep(i,n+1) mins(ans,dp[i]);
rep(i,n) {
ll l = p.back().fi, r = p.back().se;
int j = n-1-i;
mins(ans, d[i]+r*i+l*j);
}
// {
// vl dp(1,LINF);
// dp[0] = 0;
// vl d;
// rep(k,n) {
// d = vl(k+2,LINF);
// swap(dp,d);
// ll l = p[k].fi, r = p[k].se, w = r+l;
// rep(j,k+1) {
// int g = k-j;
// mins(dp[j], d[j]+r+w*g);
// mins(dp[j+1], d[j]+l+w*j);
// }
// }
// }
cout<<ans<<endl;
return 0;
}
Submission Info
Submission Time
2016-11-28 13:15:57+0900
Task
F - Intervals
User
snuke
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
3148 Byte
Status
WA
Exec Time
37 ms
Memory
512 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:66:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:70:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,n) scanf("%d%d",&p[i].fi,&p[i].se);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 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
37 ms
384 KB
001.txt
AC
9 ms
384 KB
002.txt
AC
36 ms
384 KB
003.txt
WA
28 ms
384 KB
004.txt
AC
36 ms
384 KB
005.txt
AC
15 ms
384 KB
006.txt
AC
36 ms
384 KB
007.txt
AC
19 ms
384 KB
008.txt
AC
36 ms
384 KB
009.txt
AC
6 ms
256 KB
010.txt
AC
37 ms
512 KB
011.txt
AC
17 ms
384 KB
012.txt
AC
36 ms
384 KB
013.txt
AC
5 ms
256 KB
014.txt
AC
36 ms
384 KB
015.txt
AC
9 ms
384 KB
016.txt
AC
36 ms
384 KB
017.txt
AC
28 ms
384 KB
018.txt
AC
36 ms
384 KB
019.txt
AC
18 ms
384 KB
020.txt
AC
3 ms
256 KB
021.txt
AC
2 ms
256 KB
022.txt
AC
36 ms
384 KB
023.txt
AC
36 ms
384 KB
024.txt
AC
36 ms
384 KB
025.txt
AC
36 ms
384 KB
026.txt
AC
36 ms
384 KB
027.txt
AC
36 ms
384 KB
028.txt
AC
36 ms
384 KB
029.txt
AC
36 ms
384 KB
030.txt
AC
36 ms
384 KB
031.txt
AC
36 ms
384 KB
032.txt
AC
36 ms
384 KB
033.txt
AC
36 ms
384 KB
034.txt
AC
36 ms
384 KB
035.txt
AC
36 ms
384 KB
036.txt
AC
36 ms
384 KB
037.txt
AC
36 ms
384 KB
038.txt
AC
36 ms
384 KB
039.txt
AC
36 ms
384 KB
040.txt
AC
36 ms
384 KB
041.txt
AC
36 ms
384 KB
042.txt
AC
36 ms
384 KB
example0.txt
AC
3 ms
256 KB
example1.txt
AC
2 ms
256 KB