mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
#13244. 「CSP2022模拟赛0913」罚抄
http://www.nfls.com.cn:10611/submission/237162
This commit is contained in:
parent
de8d986270
commit
978cd55503
64
NFLSOJ/13244/13244.cpp
Normal file
64
NFLSOJ/13244/13244.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// #include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// using std::cin;
|
||||||
|
// using std::cout;
|
||||||
|
std::ifstream cin("rewrite.in");
|
||||||
|
std::ofstream cout("rewrite.out");
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 5005;
|
||||||
|
|
||||||
|
int n;
|
||||||
|
long long f[N][N][2];
|
||||||
|
bool flag = false;
|
||||||
|
std::pair<int, int> a[N];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1, l, r; i <= n; i++) {
|
||||||
|
cin >> a[i].first >> a[i].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n % 2) {
|
||||||
|
flag = true;
|
||||||
|
} else {
|
||||||
|
a[++n] = std::make_pair(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(f, 0x3f, sizeof(f));
|
||||||
|
std::sort(a + 1, a + n + 1, [&](const std::pair<int, int> &lhs, const std::pair<int, int> &rhs) -> bool { return lhs.second - lhs.first > rhs.second - rhs.first; });
|
||||||
|
|
||||||
|
f[0][0][0] = 0;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (i == n || flag) {
|
||||||
|
for (int j = 0; j <= i; j++) {
|
||||||
|
f[i][j][1] = f[i - 1][j][0] + static_cast<long long>(n >> 1) * (a[i].second - a[i].first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j <= i; j++) {
|
||||||
|
if (j) {
|
||||||
|
f[i][j][0] = std::min(f[i][j][0], f[i - 1][j - 1][0] + static_cast<long long>(j - 1) * (a[i].second - a[i].first) + a[i].second);
|
||||||
|
f[i][j][1] = std::min(f[i][j][1], f[i - 1][j - 1][1] + static_cast<long long>(j - 1) * (a[i].second - a[i].first) + a[i].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j != i) {
|
||||||
|
f[i][j][0] = std::min(f[i][j][0], f[i - 1][j][0] + static_cast<long long>(i - j - 1) * (a[i].second - a[i].first) - a[i].first);
|
||||||
|
f[i][j][1] = std::min(f[i][j][1], f[i - 1][j][1] + static_cast<long long>(i - j - 2) * (a[i].second - a[i].first) - a[i].first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << f[n][n >> 1][1] << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
NFLSOJ/13244/samples/ex_rewrite1.in
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite1.out
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite2.in
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite2.out
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite3.in
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite3.out
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite4.in
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
NFLSOJ/13244/samples/ex_rewrite4.out
(Stored with Git LFS)
Normal file
BIN
NFLSOJ/13244/samples/ex_rewrite4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user