QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217369 | #7118. Closing Time | hocky# | 17 | 52ms | 37600kb | C++14 | 3.4kb | 2023-10-16 20:06:01 | 2024-04-28 07:53:16 |
Judging History
answer
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i = a;i < b;i++)
#define trav(nx, v) for(auto &nx : v)
#define all(a) begin(a), end(a)
#define sz(v) (int) v.size()
int n;
typedef array<LL, 4> CostNodeFrom;
CostNodeFrom plain = {-1,-1,-1,-1};
multiset<CostNodeFrom> prim;
const int LIM = 200000;
vector <PLL> edge[LIM + 5];
bool isInside[LIM + 5][2];
LL curans[LIM + 5];
CostNodeFrom cheap[LIM + 5][2];
ostream& operator<<(ostream &os, CostNodeFrom c) {
os <<"(" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] <<")";
return os;
}
void fixHeuristics(int node){
//~ cout << "Heur " << node << endl;
auto average = (cheap[node][0][0] + cheap[node][1][0]) / 4;
//~ cout << average << endl;
prim.erase(prim.find(cheap[node][0]));
prim.erase(prim.find(cheap[node][1]));
cheap[node][0][0] = average;
cheap[node][1][0] = average;
prim.insert(cheap[node][0]);
prim.insert(cheap[node][1]);
}
void updateCheap(int node, LL val, bool isY) {
//~ cout << "Updating " << node << " " << val << endl;
cheap[node][isY] = plain;
if(cheap[node][!isY][1] != -1) {
prim.erase(prim.find(cheap[node][!isY]));
curans[node] += val;
cheap[node][!isY][0] = max(0LL, cheap[node][!isY][3] - curans[node]);
prim.insert(cheap[node][!isY]);
} else {
curans[node] += val;
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W){
//~ cout << LLONG_MAX << endl;
K *= 4;
n = N;
rep(i,0,N) {
edge[i].clear();
isInside[i][0] = isInside[i][1] = 0;
curans[i] = 0;
cheap[i][0] = cheap[i][1] = plain;
}
//~ cout << "Here " << U[0] << " " << V[0] << "" << W[0] << endl;
prim.clear();
rep(i,0,N - 1){
auto tmp = 4LL * W[i];
if(tmp > K) continue;
//~ cout << U[i] << " " << V[i] << endl;
edge[U[i]].emplace_back(V[i], tmp);
edge[V[i]].emplace_back(U[i], tmp);
}
isInside[X][0] = 1;
isInside[Y][1] = 1;
LL ans = 2;
trav(tmp, edge[X]){
CostNodeFrom nx = {tmp.se, tmp.fi, 0, tmp.se};
prim.insert(nx);
cheap[tmp.fi][0] = nx;
}
trav(tmp, edge[Y]) {
CostNodeFrom nx = {tmp.se, tmp.fi, 1, tmp.se};
prim.insert(nx);
cheap[tmp.fi][1] = nx;
if(cheap[tmp.fi][0][1] != -1){
fixHeuristics(tmp.fi);
}
}
while(sz(prim)){
auto currentTop = *prim.begin();
//~ cout << "here K = " << K << " relaxing node " << currentTop[1] << " with heuristic " << currentTop[0] << " from node " << currentTop[2] << endl;
prim.erase(prim.begin());
auto realCost = max(0LL, currentTop[3] - curans[currentTop[1]]);
if(K < realCost) continue;
updateCheap(currentTop[1], realCost, currentTop[2]);
trav(cur, edge[currentTop[1]]){
if(isInside[cur.fi][currentTop[2]]) continue;
auto addCost = max(currentTop[3] + cur.se - curans[cur.fi], 0LL);
CostNodeFrom nxCheap = {addCost, cur.fi, currentTop[2], currentTop[3] + cur.se};
cheap[cur.fi][currentTop[2]] = nxCheap;
prim.insert(nxCheap);
// Add heuristics
if(cheap[cur.fi][!currentTop[2]][1] != -1){
fixHeuristics(cur.fi);
}
}
K -= realCost;
ans++;
isInside[currentTop[1]][currentTop[2]] = 1;
}
//~ rep(i,0,n){
//~ cout << curans[i] / 4 << " ";
//~ }
//~ cout << endl;
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 49ms
memory: 37600kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 31011 61157 8517583098 31011 129396 964383 1655 129396 331139 1655 191487 566483 110385 191487 865248 43212 110385 542661 43212 81682 13766 81682 91774 546589 91774 124706 780638 124706 175650 118706 10421 175650 615314 10421 151953 436270 140430 151...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 451
result:
ok
Test #2:
score: 8
Accepted
time: 52ms
memory: 37564kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 97133 170892 35489415917 114511 170892 730058 34783 114511 435023 34783 47301 562314 47301 162600 457629 44856 162600 365133 44856 133801 83016 117539 133801 124222 117539 128719 199821 77871 128719 703141 77871 133155 624331 7211 133155 138691 7211 ...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 650
result:
ok
Test #3:
score: 8
Accepted
time: 31ms
memory: 13084kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 200 1000 611 992 5736784 504 611 954658 504 936 219278 502 936 632439 393 502 177662 267 393 570266 267 291 941365 291 310 168052 310 765 253098 635 765 724932 274 635 842125 274 799 848645 39 799 433118 39 940 705598 553 940 564063 553 960 69665 917 960 6904...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 126 38 69 34 52 33 42 32 39 41 38 36 45 84 40 44 50 42 47 34 38 47 38 37 39 37 44 39 32 33 38 54 25 36 46 33 37 35 28 36 45 43 44 49 37 33 43 44 53 42 33 30 50 41 37 40 37 44 207 31 37 45 36 43 35 40 41 39 135 53 40 32 31 37 34 38 51 48 36 40 48 42 43 43 3...
result:
ok
Subtask #2:
score: 9
Accepted
Test #4:
score: 9
Accepted
time: 0ms
memory: 12464kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 23 25 382806473 0 1 375710 1 2 898637 2 3 10402 3 4 536577 4 5 385023 5 6 71075 6 7 543368 7 8 301497 8 9 174394 9 10 711312 10 11 923006 11 12 675532 12 13 838667 13 14 565729 14 15 979816 15 16 862618 16 17 576015 17 18 177751 18 19 306989 19 20 881492...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 96
result:
ok
Test #5:
score: 9
Accepted
time: 2ms
memory: 11732kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 47 20 22 25669694 0 1 291237 1 2 851987 2 3 421247 3 4 962919 4 5 643085 5 6 224951 6 7 756890 7 8 147295 8 9 625823 9 10 736374 10 11 290526 11 12 335466 12 13 539086 13 14 957449 14 15 423408 15 16 932444 16 17 356032 17 18 307118 18 19 94279 19 20 989546...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 26
result:
ok
Test #6:
score: 9
Accepted
time: 2ms
memory: 12284kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 46 6 34 355277954 0 1 574359 1 2 58362 2 3 778155 3 4 538832 4 5 128903 5 6 79774 6 7 715282 7 8 259924 8 9 640303 9 10 361135 10 11 506866 11 12 527045 12 13 946672 13 14 620381 14 15 701743 15 16 766266 16 17 524732 17 18 340089 18 19 630172 19 20 357712 ...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 74
result:
ok
Test #7:
score: 9
Accepted
time: 0ms
memory: 12012kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 45 14 44 70669 0 1 266130 1 2 372315 2 3 965349 3 4 119493 4 5 190522 5 6 506822 6 7 45330 7 8 423189 8 9 748532 9 10 653554 10 11 102552 11 12 90431 12 13 843259 13 14 422626 14 15 35334 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 4
result:
ok
Test #8:
score: 9
Accepted
time: 2ms
memory: 12404kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 0 49 332340134 0 1 987193 1 2 950856 2 3 893737 3 4 870689 4 5 810192 5 6 790242 6 7 744052 7 8 714922 8 9 677074 9 10 630082 10 11 599644 11 12 528415 12 13 491648 13 14 479486 14 15 439182 15 16 371085 16 17 357776 17 18 308161 18 19 254481 19 20 20430...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 44
result:
ok
Test #9:
score: 9
Accepted
time: 3ms
memory: 11956kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 0 49 329827838 0 1 972981 1 2 953594 2 3 908629 3 4 849675 4 5 808354 5 6 782643 6 7 759387 7 8 698618 8 9 650896 9 10 639153 10 11 591828 11 12 532588 12 13 503214 13 14 447660 14 15 403224 15 16 380834 16 17 327127 17 18 300115 18 19 244025 19 20 23362...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 44
result:
ok
Test #10:
score: 9
Accepted
time: 2ms
memory: 12216kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 3 0 1 1 0 1 1 1 2 1
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 3
result:
ok
Test #11:
score: 9
Accepted
time: 0ms
memory: 11028kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 20 8 9 31897732 0 1 428932 1 2 103619 2 3 805647 3 4 691922 4 5 320369 5 6 755877 6 7 701672 7 8 426711 8 9 507102 9 10 492732 10 11 68466 11 12 317311 12 13 37666 13 14 499673 14 15 502226 15 16 753200 16 17 523387 17 18 904778 18 19 695859
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 30
result:
ok
Test #12:
score: 9
Accepted
time: 2ms
memory: 12088kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 20 15 16 25160185 0 1 193268 1 2 139314 2 3 193167 3 4 446469 4 5 793626 5 6 502774 6 7 598587 7 8 69975 8 9 499282 9 10 943594 10 11 804459 11 12 536095 12 13 578060 13 14 142523 14 15 364845 15 16 181397 16 17 64327 17 18 224827 18 19 439557
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 26
result:
ok
Test #13:
score: 9
Accepted
time: 2ms
memory: 11096kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 20 0 19 77846543 0 1 603320 1 2 433257 2 3 572719 3 4 340716 4 5 549198 5 6 383420 6 7 50703 7 8 720210 8 9 304217 9 10 162280 10 11 68594 11 12 401595 12 13 446738 13 14 920882 14 15 494739 15 16 616729 16 17 874820 17 18 269830 18 19 53532
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 34
result:
ok
Test #14:
score: 9
Accepted
time: 2ms
memory: 12048kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 19 2 17 6692 0 1 748749 1 2 369010 2 3 3351 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 3346 17 18 11355
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 3
result:
ok
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #15:
score: 0
Time Limit Exceeded
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 25 20 9 16 34385 0 1 196 1 2 733 2 3 758 3 4 92 4 5 636 5 6 462 6 7 491 7 8 239 8 9 873 9 10 983 10 11 72 11 12 988 12 13 690 13 14 162 14 15 287 15 16 247 16 17 121 17 18 140 18 19 64 20 9 13 37109 0 1 530 1 2 588 2 3 841 3 4 274 4 5 994 5 6 879 6 7 879 7 8 ...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 9
Accepted
time: 3ms
memory: 11440kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 6
result:
ok
Test #37:
score: 9
Accepted
time: 0ms
memory: 11532kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 8 0 2 2 1 2 3 2 3 100
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 5
result:
ok
Test #38:
score: 0
Wrong Answer
time: 2ms
memory: 10808kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 8 0 4 84 0 1 1 1 2 29 2 3 29 3 4 1 4 5 20 2 6 20 3 7 1
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 8
result:
wrong answer 1st lines differ - on the 1st token, expected: '9', found: '8'
Subtask #6:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%