QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235963#7118. Closing Time275307894a8 125ms40844kbC++142.1kb2023-11-03 14:11:132024-04-28 07:57:57

Judging History

你现在查看的是最新测评结果

  • [2024-04-28 07:57:57]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:125ms
  • 内存:40844kb
  • [2023-11-03 14:11:13]
  • 评测
  • 测评结果:8
  • 用时:114ms
  • 内存:41240kb
  • [2023-11-03 14:11:13]
  • 提交

answer

#include "closing.h"
#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=5e5+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n;ll k;vector<pii> S[N];
ll d1[N],d2[N];
void Make(int x,int La,ll *d){
	for(auto i:S[x]) if(i.fi^La) d[i.fi]=d[x]+i.se,Make(i.fi,x,d);
}
int max_score(int nn,int X,int Y,ll kk,vector<int> U,vector<int> V,vector<int> W){
    int i,j;n=nn;k=kk;for(i=0;i<n;i++) S[i].clear();
	for(int i=0;i<n-1;i++) S[U[i]].emplace_back(V[i],W[i]),S[V[i]].emplace_back(U[i],W[i]);
	d1[X]=d2[Y]=0;Make(X,-1,d1);Make(Y,-1,d2);
	k*=2;
	for(int i=0;i<n;i++) d1[i]*=2,d2[i]*=2;
	priority_queue<pair<ll,int> > q;
	int ans=0, tot=0;
	for(i=0;i<n;i++) q.emplace(-d1[i],0),q.emplace(-d2[i],0);
	ll m=k;
	while(!q.empty()){
		auto p=q.top();q.pop();
		p.fi*=-1;
		if(m>=p.fi) m-=p.fi,tot++;
		else break;
	}
	ans=max(ans,tot);
	while(!q.empty()) q.pop();
	tot=0;m=k;
	for(i=0;i<n;i++) {
		if(d1[i]>d2[i]) swap(d1[i],d2[i]);
	}
	ll Le=d1[X]+d2[X];
	for(i=0;i<n;i++){
		if(d1[i]+d2[i]==Le){
			tot++;m-=min(d1[i],d2[i]);
			q.emplace(-abs(d1[i]-d2[i]),1);
		}else {
			d2[i]-=d1[i];
			if(d1[i]<=d2[i]) q.emplace(-d1[i],0),q.emplace(-d2[i],1);
			else q.emplace(-(d1[i]+d2[i])/2,-i);
		}
	} 
	ll mm=0;
	while(!q.empty()){
		auto p=q.top();q.pop();p.fi*=-1;p.se*=-1;
		// cerr<<tot<<' '<<m<<' '<<p.fi<<' '<<p.se<<'\n';
		if(m<p.fi) break;
		if(p.se==-1) {m-=p.fi;mm=max(mm,p.fi);tot++;continue;}
		if(m>=d1[p.se]+d2[p.se]) {m-=d1[p.se]+d2[p.se];tot+=2;continue;}
		if(m+mm>=d1[p.se]+d2[p.se]) {
			tot++;
			break;
		}
		q.emplace(-d1[p.se],1);
	}
	cerr<<m<<'\n';
	if(m>=0) ans=max(ans,tot);
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 106ms
memory: 36544kb

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: 125ms
memory: 40844kb

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: 66ms
memory: 12624kb

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: 2ms
memory: 11440kb

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
92

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '92'

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: 10652kb

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: 0ms
memory: 10064kb

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
Wrong Answer
time: 2ms
memory: 10660kb

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
10

result:

wrong answer 1st lines differ - on the 1st token, expected: '9', found: '10'

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%