QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217361 | #7118. Closing Time | hocky# | 0 | 2ms | 12572kb | C++14 | 3.3kb | 2023-10-16 20:00:54 | 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 " << 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][1][0] != -1){
fixHeuristics(tmp.fi);
}
}
while(sz(prim)){
auto currentTop = *prim.begin();
//~ cout << "here K = " << K << " relaxing node " << currentTop[1] << " with cost " << 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: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
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:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Test #36:
score: 9
Accepted
time: 2ms
memory: 11716kb
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: 0
Accepted
time: 2ms
memory: 12572kb
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: -9
Runtime Error
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:
result:
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%