QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166394 | #7118. Closing Time | youngsystem# | 8 | 90ms | 46212kb | C++14 | 3.0kb | 2023-09-06 10:54:17 | 2024-04-28 07:31:48 |
Judging History
answer
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
long long disx[200005],disy[200005];
vector<pair<int,int> >v[200005];
int fa[200005];
bool lj[200005];
void dfsx(int x,int f)
{
fa[x]=f;
for(int i=0;i<v[x].size();i++)
{
int sth=v[x][i].first,bq=v[x][i].second;
if(sth==f)continue;
disx[sth]=disx[x]+bq;
dfsx(sth,x);
}
}
void dfsy(int x,int f)
{
for(int i=0;i<v[x].size();i++)
{
int sth=v[x][i].first,bq=v[x][i].second;
if(sth==f)continue;
disy[sth]=disy[x]+bq;
dfsy(sth,x);
}
}
long long dis1[200005],dis2[200005];
long long dp[3005][6005];
long long qz[400005];
int sy[200005];
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > >pq,pq2;
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
for(int i=1;i<=N;i++)v[i].clear(),sy[i]=0;
while(!pq.empty())pq.pop();
while(!pq2.empty())pq2.pop();
for(int i=0;i<N-1;i++)
{
U[i]++;
V[i]++;
v[U[i]].push_back(make_pair(V[i],W[i]));
v[V[i]].push_back(make_pair(U[i],W[i]));
}
X++;
Y++;
disx[X]=disy[Y]=0;
dfsx(X,0);
dfsy(Y,0);
int sth=Y;
while(sth!=0)
{
lj[sth]=true;
sth=fa[sth];
}
int ans1=N;
for(int i=1;i<=N;i++)
{
dis1[i]=min(disx[i],disy[i]);
dis2[i]=max(disx[i],disy[i]);
qz[i]=dis1[i];
//printf("%lld %lld\n",dis1[i],dis2[i]);
}
sort(qz+1,qz+N+1);
long long now=0;
for(int i=1;i<=N;i++)
{
now+=qz[i];
if(now>K)
{
ans1=i-1;
break;
}
}
int ans2=0;
int nsl=0;
long long het=0;
for(int i=1;i<=N;i++)
{
if(lj[i])
{
nsl++;
het+=dis1[i];
sy[i]=1;
pq.push(make_pair(dis2[i]-dis1[i],i));
}
else
{
if(dis1[i]<dis2[i]-dis1[i])
{
pq.push(make_pair(dis1[i],i));
pq.push(make_pair(dis2[i]-dis1[i],i));
}
else
{
pq2.push(make_pair(dis2[i],i));
}
}
}
if(het>K)return ans1;
while(!pq2.empty())
{
pair<long long,int> sth=pq2.top();
//printf("!!!%lld %d\n",sth.first,sth.second);
if(het+sth.first>K)
{
break;
}
if(pq.size()<=1)
{
het+=sth.first;
sy[sth.second]+=2;
nsl+=2;
pq2.pop();
continue;
}
pair<long long,int> x=pq.top();
pq.pop();
pair<long long,int> y=pq.top();
if(x.first+y.first<sth.first)
{
//printf("pq:%lld %d\n",x.first,x.second);
het+=x.first;
sy[x.second]+=1;
nsl++;
}
else
{
//printf("pq2:%lld %d\n",sth.first,sth.second);
het+=sth.first;
nsl+=2;
sy[sth.second]+=2;
pq.push(x);
pq2.pop();
}
}
//printf("!!!%lld %d\n",het,nsl);
int tmp=0;
for(int i=1;i<=N;i++)
{
if(sy[i]==0)
{
qz[++tmp]=dis1[i];
}
if(sy[i]<2)
{
qz[++tmp]=dis2[i]-dis1[i];
}
}
sort(qz+1,qz+tmp+1);
for(int i=1;i<=tmp;i++)
{
if(het+qz[i]<=K)
{
het+=qz[i];
nsl++;
}
}
//printf("!!!%lld %d\n",het,nsl);
ans2=nsl;
return max(ans1,ans2);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 89ms
memory: 41620kb
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: 90ms
memory: 46212kb
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: 56ms
memory: 21020kb
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: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 3ms
memory: 16132kb
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 98
result:
wrong answer 1st lines differ - on the 1st token, expected: '96', found: '98'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 9
Accepted
time: 0ms
memory: 14368kb
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: 3ms
memory: 14348kb
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
Accepted
time: 3ms
memory: 14136kb
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 9
result:
ok
Test #39:
score: 9
Accepted
time: 3ms
memory: 18144kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 18 14 15 221112 8 10 15984 3 8 2664 6 10 5328 9 10 13320 5 10 23976 1 10 13320 3 4 5328 3 7 26640 3 11 23976 4 15 23976 6 17 18648 12 17 5328 11 13 13320 0 11 7992 15 16 5328 2 16 5328 13 14 2664
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 14
result:
ok
Test #40:
score: 9
Accepted
time: 3ms
memory: 16392kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 19 3 9 11232111 13 14 174955 0 13 69982 10 14 209946 14 15 209946 12 14 104973 0 11 314919 0 3 314919 0 7 139964 5 10 209946 10 16 69982 4 10 104973 9 11 279928 9 17 349910 1 4 104973 3 18 209946 6 18 174955 7 8 314919 2 7 104973
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 28
result:
ok
Test #41:
score: 9
Accepted
time: 0ms
memory: 18120kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 15 5 7 155966 1 4 964448 5 11 996819 9 10 330180 5 6 987448 11 12 704605 0 5 155967 8 14 596631 10 11 923917 0 14 560902 4 13 49411 1 7 856694 1 12 755799 2 14 488208 3 13 990480
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 2
result:
ok
Test #42:
score: 9
Accepted
time: 0ms
memory: 18440kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 20 4 7 40726445 15 18 841797 9 16 909512 0 7 39919 8 19 78725 6 17 661904 7 14 426400 17 18 664669 7 13 917960 4 14 821652 4 11 274656 1 12 937782 10 19 129031 12 13 504353 5 11 502915 3 8 264525 2 19 358409 12 18 578659 16 19 696491 3 17 175157
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 30
result:
ok
Test #43:
score: 9
Accepted
time: 0ms
memory: 16104kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 19 1 8 758761123780644886 3 18 947982 12 13 415218 3 15 890432 11 17 808801 2 8 726510 7 12 752493 8 17 328133 6 7 465830 8 14 126540 9 18 443041 1 7 605214 4 11 243452 9 10 106626 3 7 498126 1 4 39081 0 2 861168 5 15 69635 3 16 223395
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 38
result:
ok
Test #44:
score: 9
Accepted
time: 0ms
memory: 14048kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 18 4 10 8410500 14 16 912609 2 8 546082 2 12 129063 1 17 454917 15 17 85372 1 11 862697 4 11 428830 7 9 860609 8 10 119165 6 11 143393 14 17 789886 13 15 216341 4 5 56300 12 13 718046 0 7 354300 9 15 142154 1 3 310843
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 11
result:
ok
Test #45:
score: 9
Accepted
time: 0ms
memory: 16136kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 18 14 15 23103649 0 6 382587 2 4 23201 2 3 58517 0 10 982598 0 17 283539 13 14 944945 4 6 576463 8 14 941541 7 16 566937 1 11 185982 3 9 360540 1 5 441702 4 16 808047 3 14 154737 3 15 344378 9 11 631318 7 12 552451
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 36
result:
ok
Test #46:
score: 9
Accepted
time: 3ms
memory: 16100kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 18 7 13 25604 13 17 12802 5 14 39262 6 8 774165 2 11 834406 5 6 1 0 16 432886 3 6 1 2 14 272481 5 12 817066 4 9 40750 15 17 889075 1 7 12804 4 16 406687 5 17 1 3 10 875945 0 1 525803 1 3 1
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 3
result:
ok
Test #47:
score: 9
Accepted
time: 3ms
memory: 16396kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 19 0 8 951764 0 1 4 1 2 4 2 3 4 3 4 307858 4 5 307858 5 6 4 6 7 4 7 8 4 4 9 121363 7 10 4 8 11 214606 5 12 999998 6 13 1000000 1 14 999995 10 15 999997 1 16 999994 13 17 999996 3 18 999991
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 13
result:
ok
Test #48:
score: 0
Wrong Answer
time: 0ms
memory: 18176kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 20 0 8 274829 0 1 2 1 2 2 2 3 2 3 4 2 4 5 2 5 6 2 6 7 2 7 8 2 4 9 548538 7 10 2 8 11 274686 6 12 999999 0 13 999995 6 14 999992 9 15 1000000 0 16 999997 9 17 999996 3 18 999998 0 19 999999
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 26
result:
wrong answer 1st lines differ - on the 1st token, expected: '21', found: '26'
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:
100%
Accepted
Dependency #2:
0%