Submission #1005350
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
template<int... Sizes>
struct MultidimensionalIndex;
template<>
struct MultidimensionalIndex<> {
MultidimensionalIndex() {}
int getTotalSize() const { return 1; }
int getIndexAcc(int acc) const { return acc; }
};
template<int Head, int... Tail>
struct MultidimensionalIndex<Head, Tail...> : MultidimensionalIndex<Tail...> {
using Base = MultidimensionalIndex<Tail...>;
enum { size = Head };
template<typename... TailT>
MultidimensionalIndex(TailT... tail) : Base(tail...) {}
int getTotalSize() const { return size * Base::getTotalSize(); }
template<typename... TailT>
int getIndexAcc(int acc, int head, TailT... tail) const { return Base::getIndexAcc(acc * size + head, tail...); }
};
template<int... Tail>
struct MultidimensionalIndex<0, Tail...> : MultidimensionalIndex<Tail...> {
using Base = MultidimensionalIndex<Tail...>;
const int size;
template<typename... TailT>
MultidimensionalIndex(int head, TailT... tail) : size(head), MultidimensionalIndex<Tail...>(tail...) {}
int getTotalSize() const { return size * Base::getTotalSize(); }
template<typename... TailT>
int getIndexAcc(int acc, int head, TailT... tail) const { return Base::getIndexAcc(acc * size + head, tail...); }
};
template<typename Val, int... Sizes>
struct DP : MultidimensionalIndex<Sizes...> {
using Base = MultidimensionalIndex<Sizes...>;
std::vector<Val> dp;
template<typename... SizesT>
DP(Val init, SizesT... sizes) : Base(sizes...), dp(Base::getTotalSize(), init) {}
template<typename... SizesT>
Val &operator()(SizesT... indices) { return dp[Base::getIndexAcc(0, indices...)]; }
template<typename... SizesT>
Val operator()(SizesT... indices) const { return dp[Base::getIndexAcc(0, indices...)]; }
void swap(DP &that) { dp.swap(that); }
};
struct Interval {
int L, R, X;
bool operator<(const Interval &that) const {
return X < that.X;
}
};
int main() {
int N;
while(~scanf("%d", &N)) {
vector<Interval> intervals(N);
rep(i, N) {
int L; int R;
scanf("%d%d", &L, &R);
intervals[i] = { L, R, L + R };
}
sort(intervals.begin(), intervals.end());
reverse(intervals.begin(), intervals.end());
DP<ll, 0, 0, 2> dp(INFL, N / 2 + 2, N / 2 + 2);
dp(0, 0, 0) = 0;
rep(i, N) {
const Interval a = intervals[i];
rer(l, 0, min(i, N / 2)) rep(c, 2) {
int r = i - l - c;
if(r < 0 || r > N / 2) continue;
ll x = dp(l, r, c);
if(x == INFL) continue;
amin(dp(l + 1, r, c), x + a.R + (ll)a.X * l);
amin(dp(l, r + 1, c), x + a.L + (ll)a.X * r);
if(c == 0)
amin(dp(l, r, c + 1), x + (ll)a.X * (N / 2));
}
}
ll ans = dp(N / 2, N / 2, N % 2);
printf("%lld\n", ans);
}
return 0;
}
Submission Info
Submission Time
2016-12-02 15:24:38+0900
Task
F - Intervals
User
anta
Language
C++14 (GCC 5.4.1)
Score
1000
Code Size
3317 Byte
Status
AC
Exec Time
227 ms
Memory
98176 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:66:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &L, &R);
^
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
224 ms
98176 KB
001.txt
AC
39 ms
17664 KB
002.txt
AC
224 ms
98048 KB
003.txt
AC
167 ms
73728 KB
004.txt
AC
225 ms
98176 KB
005.txt
AC
82 ms
36224 KB
006.txt
AC
225 ms
98048 KB
007.txt
AC
109 ms
47232 KB
008.txt
AC
225 ms
98176 KB
009.txt
AC
20 ms
8832 KB
010.txt
AC
226 ms
98176 KB
011.txt
AC
89 ms
40576 KB
012.txt
AC
224 ms
98176 KB
013.txt
AC
17 ms
7296 KB
014.txt
AC
224 ms
98176 KB
015.txt
AC
39 ms
17792 KB
016.txt
AC
224 ms
98048 KB
017.txt
AC
165 ms
72320 KB
018.txt
AC
225 ms
98048 KB
019.txt
AC
99 ms
44800 KB
020.txt
AC
3 ms
256 KB
021.txt
AC
3 ms
256 KB
022.txt
AC
226 ms
98176 KB
023.txt
AC
223 ms
98048 KB
024.txt
AC
227 ms
98176 KB
025.txt
AC
224 ms
98176 KB
026.txt
AC
226 ms
98176 KB
027.txt
AC
224 ms
98048 KB
028.txt
AC
225 ms
98176 KB
029.txt
AC
222 ms
98048 KB
030.txt
AC
223 ms
98048 KB
031.txt
AC
223 ms
98048 KB
032.txt
AC
225 ms
98048 KB
033.txt
AC
224 ms
98176 KB
034.txt
AC
226 ms
98048 KB
035.txt
AC
224 ms
98048 KB
036.txt
AC
225 ms
98176 KB
037.txt
AC
224 ms
98048 KB
038.txt
AC
225 ms
98048 KB
039.txt
AC
224 ms
98048 KB
040.txt
AC
225 ms
98176 KB
041.txt
AC
223 ms
98048 KB
042.txt
AC
224 ms
98176 KB
example0.txt
AC
3 ms
256 KB
example1.txt
AC
3 ms
256 KB