Submission #1013628
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("-1"); 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 = 2505, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
ll dp[MX][MX][2];
int main() {
int n;
scanf("%d",&n);
vi a(n), b(n);
rep(i,n) scanf("%d%d",&a[i],&b[i]);
vi id(n);
rep(i,n) id[i] = i;
sort(rng(id),[&](int i, int j) { return a[i]+b[i] > a[j]+b[j];});
int m = n/2;
rep(i,m+1)rep(j,m+1)rep(k,2) dp[i][j][k] = LINF;
dp[0][0][0] = 0;
rep(i,n) {
ll x = a[id[i]];
ll y = b[id[i]];
ll w = x+y;
rep(k,2)rep(l,m+1) {
int r = i-k-l;
if (r < 0) break;
if (!k) {
mins(dp[l][r][k+1], dp[l][r][k]+w*m);
}
mins(dp[l+1][r][k], dp[l][r][k]+w*l+y);
mins(dp[l][r+1][k], dp[l][r][k]+w*r+x);
}
}
cout<<dp[m][m][n&1]<<endl;
return 0;
}
Submission Info
Submission Time
2016-12-06 01:19:26+0900
Task
F - Intervals
User
snuke
Language
C++14 (GCC 5.4.1)
Score
1000
Code Size
2819 Byte
Status
AC
Exec Time
371 ms
Memory
98304 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:68:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,n) scanf("%d%d",&a[i],&b[i]);
^
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
356 ms
98176 KB
001.txt
AC
75 ms
30464 KB
002.txt
AC
355 ms
98176 KB
003.txt
AC
279 ms
85120 KB
004.txt
AC
355 ms
98176 KB
005.txt
AC
153 ms
55424 KB
006.txt
AC
355 ms
98176 KB
007.txt
AC
192 ms
66048 KB
008.txt
AC
355 ms
98176 KB
009.txt
AC
38 ms
16128 KB
010.txt
AC
355 ms
98176 KB
011.txt
AC
167 ms
59776 KB
012.txt
AC
355 ms
98176 KB
013.txt
AC
31 ms
13440 KB
014.txt
AC
371 ms
98176 KB
015.txt
AC
78 ms
30720 KB
016.txt
AC
356 ms
98304 KB
017.txt
AC
266 ms
84224 KB
018.txt
AC
355 ms
98176 KB
019.txt
AC
184 ms
63872 KB
020.txt
AC
3 ms
256 KB
021.txt
AC
3 ms
256 KB
022.txt
AC
355 ms
98176 KB
023.txt
AC
356 ms
98176 KB
024.txt
AC
355 ms
98176 KB
025.txt
AC
355 ms
98176 KB
026.txt
AC
356 ms
98176 KB
027.txt
AC
355 ms
98176 KB
028.txt
AC
355 ms
98176 KB
029.txt
AC
355 ms
98176 KB
030.txt
AC
355 ms
98176 KB
031.txt
AC
356 ms
98176 KB
032.txt
AC
355 ms
98176 KB
033.txt
AC
355 ms
98176 KB
034.txt
AC
355 ms
98176 KB
035.txt
AC
357 ms
98176 KB
036.txt
AC
355 ms
98176 KB
037.txt
AC
355 ms
98176 KB
038.txt
AC
355 ms
98176 KB
039.txt
AC
356 ms
98176 KB
040.txt
AC
361 ms
98176 KB
041.txt
AC
354 ms
98176 KB
042.txt
AC
358 ms
98176 KB
example0.txt
AC
3 ms
256 KB
example1.txt
AC
3 ms
256 KB