QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153879 | #7118. Closing Time | Lynkcat# | 8 | 107ms | 56392kb | C++20 | 3.4kb | 2023-08-31 09:54:17 | 2023-08-31 09:54:18 |
Judging History
answer
#include "closing.h"
#include<bits/stdc++.h>
#define poly vector<ll>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < ll,ll >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
// #define int ll
// #define N
using namespace std;
void dfs(int k,int fa,poly &dis,vector<vector<pa>> &G)
{
for (auto [u,w]:G[k])
{
if (u==fa) continue;
dis[u]=dis[k]+w;
dfs(u,k,dis,G);
}
}
int max_score(int n, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
// cerr<<"!!!!!!"<<endl;
poly dx(n,0),dy(n,0);
vector<vector<pa>>G(n,vector<pa>());
for (int i=0;i+1<n;i++)
G[U[i]].push_back(mp(V[i],W[i])),
G[V[i]].push_back(mp(U[i],W[i]));
dfs(X,X,dx,G);
dfs(Y,Y,dy,G);
// cerr<<"!!!!!!"<<endl;
int ans=0;
{
priority_queue<pa>q;
vector<bool>vis(n,0);
for (int i=0;i<n;i++)
q.push(mp(-dx[i],i)),q.push(mp(-dy[i],i));
ll sm=0;
int now=0;
while (!q.empty())
{
int u=q.top().se;
ll w=-q.top().fi;
q.pop();
if (vis[u]) continue;
vis[u]=1;
sm+=w;
if (sm>K) break;
now++;
}
ans=max(ans,now);
}
{
priority_queue<pa,vector<pa>,greater<pa>>q;
priority_queue<pa>qs;
vector<int>vis(n,0);
vector<poly>val(n,poly(3,-19));
ll mn=dx[0]+dy[0];
for (int i=0;i<n;i++)
{
if (dx[i]+dy[i]<mn) mn=min(mn,dx[i]+dy[i]);
}
int now=0;
for (int i=0;i<n;i++)
if (dx[i]+dy[i]==mn) K-=min(dx[i],dy[i]),vis[i]=1,q.push(mp(abs(dx[i]-dy[i]),i)),now++;
else
{
// cout<<"!!!"<<i<<endl;
vis[i]=0;
q.push(mp(min(dx[i],dy[i]),i));
val[i][0]=min(dx[i],dy[i]);
val[i][1]=abs(dx[i]-dy[i]);
}
// cout<<"??"<<now<<" "<<K<<endl;
if (K>=0)
{
int tt=0;
while (!q.empty())
{
int u=q.top().se;
ll w=q.top().fi;
// cout<<"??"<<u<<","<<w<<'\n';
q.pop();
// cout<<"?"<<u<<" "<<w<<" "<<K<<" "<<tt<<" "<<q.size()<<endl;
if (w!=val[u][vis[u]]||tt==n) continue;
if (K<w)
{
tt++;
if (qs.size()&&K+qs.top().fi-w>=0)
{
int v=qs.top().se;
K+=qs.top().fi-w;
vis[v]--;
qs.pop();
qs.push(mp(val[u][vis[u]],u));
vis[u]++;
q.push(mp(val[v][vis[v]],v));
}
} else
{
tt=0;
// cerr<<"ins "<<u<<" "<<w<<endl;
K-=w;
qs.push(mp(val[u][vis[u]],u));
vis[u]++;
if (vis[u]<=1) q.push(mp(val[u][vis[u]],u));
now++;
}
}
ans=max(ans,now);
}
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 99ms
memory: 50268kb
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: 0
Accepted
time: 107ms
memory: 56392kb
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: 0
Accepted
time: 65ms
memory: 6304kb
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: 9
Accepted
time: 1ms
memory: 3672kb
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: 0
Accepted
time: 1ms
memory: 3680kb
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
Wrong Answer
time: 1ms
memory: 3672kb
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 59
result:
wrong answer 1st lines differ - on the 1st token, expected: '74', found: '59'
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: 0
Wrong Answer
time: 1ms
memory: 3756kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 5
result:
wrong answer 1st lines differ - on the 1st token, expected: '6', found: '5'
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%