QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94048 | #6122. Impossible-to-finish Race | sinbad# | TL | 1629ms | 158200kb | C++ | 4.7kb | 2023-04-05 08:44:25 | 2023-04-05 08:44:27 |
Judging History
answer
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}
using int64 = long long;
using int128 = __int128_t;
using ii = pair<int, int>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
constexpr inline int lg2(int64 x) { return x == 0 ? -1 : sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
constexpr inline int p2ceil(int64 x) { return 1 << (lg2(x - 1) + 1); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
inline void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
inline void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }
inline int mod(int x) { return x >= MOD ? x - MOD : x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
int main() {
int n, m;
cin >> n >> m;
vector<array<int, 2>> a(n); // H, A
for (int i = 0; i < n; ++i) cin >> a[i][1] >> a[i][0];
sort(a.begin(), a.end());
trace(a);
vector<int> best(n);
best[n - 1] = a[n - 1][1] - a[n - 1][0];
for (int i = n - 2; i >= 0; --i) best[i] = max(best[i + 1], a[i][1] - a[i][0]);
trace(best);
auto dp = vect<int64>(-1, n, m);
auto vis = vect<bool>(0, n, m);
function<int64(int, int)> solve =
[&](int pos, int cnt) -> int64 {
if (pos == n) return -inf<int64>;
if (cnt == m - 1) return best[pos];
if (vis[pos][cnt]) return dp[pos][cnt];
dp[pos][cnt] = -inf<int64>;
// pick
ckmax(dp[pos][cnt], solve(pos + 1, cnt + 1) + a[pos][1] + (cnt == 0 ? a[pos][0] : 0));
// no pick
ckmax(dp[pos][cnt], solve(pos + 1, cnt));
vis[pos][cnt] = 1;
return dp[pos][cnt];
};
int64 ret = solve(0, 0);
cout << ret << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3396kb
input:
4 2 40 150 100 185 60 160 80 170
output:
165
result:
ok 1 number(s): "165"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
4 3 40 150 100 185 60 160 80 170
output:
215
result:
ok 1 number(s): "215"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
4 3 40 150 100 300 60 160 80 140
output:
160
result:
ok 1 number(s): "160"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3424kb
input:
10 5 31 41 59 26 53 58 97 93 23 84 62 64 33 83 27 95 2 84 19 71
output:
237
result:
ok 1 number(s): "237"
Test #5:
score: 0
Accepted
time: 253ms
memory: 48632kb
input:
41152 111 182257016 930588061 48161946 238486760 972227016 5356065 86027096 260499041 669036106 225099150 237412554 751531756 242943966 295403431 389306712 171941587 805402434 808802744 223087510 185548988 484802407 630362813 909265069 146703978 669049492 795632652 880214973 687316602 917988759 1140...
output:
110260223222
result:
ok 1 number(s): "110260223222"
Test #6:
score: 0
Accepted
time: 418ms
memory: 72244kb
input:
48742 151 4172512 232468953 174593775 315428416 755598560 502830675 153875037 669103745 655189533 251356834 742835852 504736254 57702809 81033220 522268929 496624663 916420651 11925854 636090457 18793771 59670306 212773533 266630484 168697702 249848762 90639194 167795884 521046550 275829432 75048104...
output:
150042793971
result:
ok 1 number(s): "150042793971"
Test #7:
score: 0
Accepted
time: 117ms
memory: 21208kb
input:
10832 185 384369718 813482411 710792603 515157830 552246538 364938172 118387323 558137174 960264583 110630 883245504 400769573 912502469 245524014 160032703 685924756 784192091 291966573 855188194 828271633 957837360 194604250 571403510 177773109 746568096 669989013 294755059 430843816 570306962 862...
output:
182319609909
result:
ok 1 number(s): "182319609909"
Test #8:
score: 0
Accepted
time: 191ms
memory: 33048kb
input:
18148 181 317375491 959619539 283021787 485619692 474951974 984085468 295380316 824207087 152625734 650222645 190338285 195156360 311736957 338390028 289661673 796666562 605193885 709391445 466977224 332169628 524062708 562163672 676469373 606455442 487555874 770717667 492775549 65447403 154084339 9...
output:
179257349651
result:
ok 1 number(s): "179257349651"
Test #9:
score: 0
Accepted
time: 118ms
memory: 27084kb
input:
20517 119 81770998 83447880 733395187 340904766 51692224 631824159 247762158 720798400 753102635 46716151 400316097 440030572 411675274 726057252 881612034 894407953 681714230 187307136 951565981 858102613 570176402 341903964 829157317 310766291 226552528 637766332 733441545 358801637 414258293 6001...
output:
117841021264
result:
ok 1 number(s): "117841021264"
Test #10:
score: 0
Accepted
time: 1629ms
memory: 158200kb
input:
93044 182 813695274 153887021 542126825 663951320 364280184 904341637 291766688 257121248 75639269 180912022 825451471 22204002 473902802 454694292 611075180 805611054 844482533 903659112 773663466 532233047 138575839 944906705 668819264 137394165 225354534 384383944 510444964 359732925 763300639 60...
output:
181211463696
result:
ok 1 number(s): "181211463696"
Test #11:
score: 0
Accepted
time: 72ms
memory: 19864kb
input:
25784 53 798294768 320766717 429746760 294501271 644419286 801462427 724066936 339399074 657789061 573676913 970005050 661268530 426332867 254169739 153700078 827586236 289134392 246530412 788279593 302899440 39720539 183658008 615865661 431061664 941027421 67440607 851264422 537004856 427260246 891...
output:
52567930451
result:
ok 1 number(s): "52567930451"
Test #12:
score: 0
Accepted
time: 831ms
memory: 101256kb
input:
85083 117 933728908 166830648 315791188 439632784 325837679 115125521 270329800 873456540 640213196 243297796 914696498 111637314 824743768 733251609 879223039 702511677 601533585 506847766 388042178 540773701 584502053 164333442 235718823 825003326 160442761 580351903 112999161 343919921 120241611 ...
output:
116486732641
result:
ok 1 number(s): "116486732641"
Test #13:
score: 0
Accepted
time: 87ms
memory: 24364kb
input:
21476 97 63429284 292081968 724418165 393470825 255101780 520874265 537856330 530859115 387052107 227378228 955779689 938747569 362382510 470288870 758017146 980866850 95193697 896397143 347630065 188685241 993612425 674170903 335151627 886335139 549751105 54769792 966979302 796574615 770088067 1448...
output:
96145475777
result:
ok 1 number(s): "96145475777"
Test #14:
score: 0
Accepted
time: 204ms
memory: 46292kb
input:
96285 26 455028034 39251727 824295989 385236424 63399198 102638857 387334356 581156661 454974662 709028736 900399312 684211451 149763651 644418604 32511388 718985488 660630420 211641780 486912715 466693387 686434645 485294856 493518359 822845210 221767398 816352162 507764176 223798302 47074048 79690...
output:
25916772196
result:
ok 1 number(s): "25916772196"
Test #15:
score: -100
Time Limit Exceeded
input:
100000 200 236287670 804039413 140506636 670751691 331381204 895007340 852265703 736737899 804066444 277236557 237844614 812494506 55084996 90201715 876812302 513418441 584034127 726487185 844521069 244127643 361613896 694711811 154016310 831976968 244847489 447480031 424060659 682670356 139039667 9...