QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#501450 | #8641. Ski 2 | green_gold_dog# | 0 | 753ms | 219180kb | C++20 | 2.5kb | 2024-08-02 18:45:50 | 2024-08-02 18:45:50 |
Judging History
answer
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
void solve() {
ll n, k;
cin >> n >> k;
map<ll, vector<ll>> all;
for (ll i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
all[x].push_back(y);
}
ll x = all.begin()->first;
sort(all[x].begin(), all[x].end());
ll cost = all[x][0];
ll ans = (all[x].size() - 1) * k;
for (ll i = 1; i < all[x].size(); i++) {
all[x + 1].push_back(all[x][i]);
}
all.erase(x);
ll nc = 0;
vector<ll> aa;
x++;
while (nc > 0 || all.lower_bound(x) != all.end()) {
aa.push_back(x);
nc += all[x].size();
if (nc <= 0) {
x = all.lower_bound(x)->first;
} else {
x++;
}
nc--;
}
aa.push_back(x);
vector<vector<vector<ll>>> dp(aa.size(), vector<vector<ll>>(n + 1, vector<ll>(n + 1, INF64)));
dp[0][0][1] = ans;
ll mcp = 0, msz = 1;
for (ll i = 0; i + 1 < aa.size(); i++) {
sort(all[aa[i]].begin(), all[aa[i]].end());
for (ll cp = 0; cp <= mcp; cp++) {
for (ll sz = 1; sz <= msz; sz++) {
ll ce = cp + all[aa[i]].size() - sz;
for (ll addsz = 0; addsz <= max(0ll, ce); addsz++) {
assign_min(dp[i + 1][max(0ll, ce - addsz)][sz + addsz], dp[i][cp][sz] + cost * addsz + max(0ll, ce - addsz) * k);
}
}
}
if (!all[aa[i]].empty()) {
assign_min(cost, all[aa[i]][0]);
}
msz += all[aa[i]].size();
mcp += all[aa[i]].size();
mcp--;
}
ans = INF64;
for (ll i = 0; i <= n; i++) {
assign_min(ans, dp.back()[0][i]);
}
cout << ans << '\n';
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
300 987761245 249 97 279 38 52 53 190 2 294 46 170 93 260 70 273 6 49 4 32 71 188 28 212 10 253 86 187 46 167 27 32 75 226 90 86 17 172 24 129 70 291 78 189 98 97 98 256 19 228 36 240 86 240 63 269 21 81 81 41 25 155 49 279 12 176 49 136 25 260 95 271 90 202 79 299 36 79 53 297 59 46 92 202 19 125 3...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #9:
score: 12
Accepted
time: 753ms
memory: 219068kb
input:
300 1 0 6596366 1 195480684 2 39457151 1 832234727 1 462764495 2 81049898 0 487070027 1 430671894 2 721333033 1 615885993 1 842070560 1 592116125 2 840818824 0 544935711 2 333187430 2 467111553 0 416912849 2 159079860 0 478546939 0 593053374 0 876528192 2 9215174 1 93255151 2 120891934 0 10339332 2 ...
output:
44543
result:
ok single line: '44543'
Test #10:
score: 12
Accepted
time: 745ms
memory: 219180kb
input:
300 1060203 0 1286878 1 960668502 2 190866228 1 195306795 1 233497287 0 343641186 0 693228127 0 67978764 2 598546069 0 751890541 0 37754998 0 305348452 1 266631431 1 844903768 1 560113131 2 47250552 0 594767495 2 809926081 0 586661105 0 366656127 0 589306393 2 416896948 2 89253046 1 363341342 0 9491...
output:
373039535
result:
ok single line: '373039535'
Test #11:
score: 12
Accepted
time: 721ms
memory: 218996kb
input:
300 1011700 0 4143879 5 61178231 1 214955252 5 577924292 3 532426729 4 862464334 4 215922747 1 602163591 2 90390184 4 709933135 1 948890772 3 784747556 2 261263945 4 784527448 3 989184114 5 465210434 3 83935742 5 876450661 3 626127035 1 699569645 1 5830291 4 974711739 0 542998610 3 604346813 1 14345...
output:
365657793
result:
ok single line: '365657793'
Test #12:
score: 12
Accepted
time: 727ms
memory: 219064kb
input:
300 2629882 0 7876717 1 380548027 4 210300855 3 804812637 0 795433451 0 696287735 1 251831535 2 510880579 5 328652705 0 850216531 5 609349591 3 66131892 5 355383071 2 846765095 2 127222407 1 933995931 0 609083290 4 506229752 1 922802380 3 277035017 2 693421958 0 339580672 4 296433175 1 933653265 2 5...
output:
732780332
result:
ok single line: '732780332'
Test #13:
score: 12
Accepted
time: 280ms
memory: 219040kb
input:
300 2161 0 4686752 8 629699716 36 412556162 10 196116733 93 237242586 45 458684505 60 125966325 2 855656971 76 750982211 88 543425907 38 355258329 92 448453464 26 608377947 93 18561617 69 644272241 23 178136181 48 306908918 32 962694105 79 683443776 28 623663382 100 501582180 92 578581062 26 8341942...
output:
10667943
result:
ok single line: '10667943'
Test #14:
score: 12
Accepted
time: 269ms
memory: 219176kb
input:
300 1264601 0 2244378 70 999535496 70 770638615 43 175588958 7 679253897 72 966146892 8 723807777 30 214248412 86 304229971 69 177589825 48 546447871 66 385401179 92 977036346 39 868966348 81 533340807 23 441268090 51 803400831 84 17907592 22 67033263 60 751134225 1 131600198 14 437904793 79 3453315...
output:
18239848
result:
ok single line: '18239848'
Test #15:
score: 0
Time Limit Exceeded
input:
300 425400 0 1915855 18 418792787 218 647548770 186 171684693 20 829774979 38 495244240 273 322971719 51 872137770 279 602534746 37 558726564 180 812007613 102 106188773 37 691630980 172 664413269 154 456050691 155 277923631 218 685494540 56 834990956 128 808406942 73 966781691 154 610439249 198 103...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #20:
score: 0
Time Limit Exceeded
input:
10 849097758 4 937762392 10 817247459 0 440668594 1 912982987 7 663812156 7 594886472 0 837105766 2 737473115 3 649275922 10 873042888
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%