QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307560#6659. 외곽 순환 도로 2Dualqwq8 33ms29500kbC++141.8kb2024-01-18 20:30:202024-08-26 15:51:44

Judging History

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

  • [2024-08-26 15:51:44]
  • 管理员手动重测本题所有提交记录
  • 测评结果:8
  • 用时:33ms
  • 内存:29500kb
  • [2024-01-18 20:30:22]
  • 评测
  • 测评结果:8
  • 用时:30ms
  • 内存:29304kb
  • [2024-01-18 20:30:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template<typename T> inline bool ckmin(T &x,const T &y) { return (x > y) && (x = y,true);}
typedef long long ll;
typedef pair<int,ll> pii;
#define FI first
#define SE second
#define mkp make_pair
int n,K;
vector<pii> G[N];
ll dp[N][2][2][2];
int L[N],R[N];
ll W[N];

void dfs0(int x,int fa) {
	if(G[x].size() == 0) { L[x] = R[x] = ++L[0];return;}
	for(auto [y,w] : G[x]) {
		if(y == fa) continue;
		dfs0(y,x);
		L[x] = min(L[x],L[y]);
		R[x] = max(R[x],R[y]);
	}
}
void dfs1(int x,int fa) {
	memset(dp[x],0x3f,sizeof dp[x]);
	if(G[x].size() == 0) { dp[x][0][0][0] = dp[x][1][1][1] = 0;return;}
	bool lst = 0;

	for(auto [y,w] : G[x]) {
		if(y == fa) continue;
		dfs1(y,x);
		if(!lst) {
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						for(int d = 0;d < 2;d++)
							ckmin(dp[x][a][c][d],dp[y][b][c][d] + (a == b) * w);
			lst = 1;
		} else {
			ll tmp[2][2][2];
			memset(tmp,0x3f,sizeof tmp);
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						for(int d = 0;d < 2;d++)
							for(int e = 0;e < 2;e++)
								for(int f = 0;f < 2;f++)
				ckmin(tmp[a][b][f],dp[x][a][b][c] + dp[y][d][e][f] + (c == e) * W[L[y] - 1] + (a == d) * w);
			for(int a = 0;a < 2;a++)
				for(int b = 0;b < 2;b++)
					for(int c = 0;c < 2;c++)
						dp[x][a][b][c] = tmp[a][b][c];
		}
	}
}
ll place_police(vector<int> P,vector<ll> C,vector<ll> _W) {
	n = P.size() + 1;K = _W.size();
	for(int i = 2;i <= n;i++)
		G[P[i - 2] + 1].emplace_back(i,C[i - 2]);
	for(int i = 1;i <= K;i++) W[i] = _W[i - 1];
	dfs0(1,0);
	dfs1(1,0);
	long long ans = 4e18;
	for(int a = 0;a < 2;a++)
		for(int b = 0;b < 2;b++)
			for(int c = 0;c < 2;c++)
				ckmin(ans,dp[1][a][b][c] + (b == c) * W[K]);
	return ans;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 1ms
memory: 7172kb

input:

5
0 452912
0 820899
0 79369
0 232463
1000000000000 1000000000000 1000000000000 1000000000000

output:

532281

result:

ok single line: '532281'

Test #2:

score: 6
Accepted
time: 1ms
memory: 7100kb

input:

6
0 581451
0 68556
0 918465
0 661406
0 41816
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1000000110372

result:

ok single line: '1000000110372'

Test #3:

score: 6
Accepted
time: 1ms
memory: 6520kb

input:

4
0 0
0 0
0 0
0 0 0

output:

0

result:

ok single line: '0'

Test #4:

score: 6
Accepted
time: 1ms
memory: 8624kb

input:

5
0 938777585449
0 576051802364
0 418735407836
0 823692221300
233950071687 338912182863 866023804654 680391493800

output:

1333076973323

result:

ok single line: '1333076973323'

Test #5:

score: 6
Accepted
time: 1ms
memory: 6784kb

input:

6
0 938777585449
0 576051802364
0 418735407836
0 823692221300
0 233950071687
338912182863 866023804654 680391493800 876313612238 476765859230

output:

991597662386

result:

ok single line: '991597662386'

Test #6:

score: 6
Accepted
time: 22ms
memory: 29500kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #7:

score: 6
Accepted
time: 20ms
memory: 23856kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

0

result:

ok single line: '0'

Test #8:

score: 6
Accepted
time: 26ms
memory: 29328kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

3

result:

ok single line: '3'

Test #9:

score: 0
Wrong Answer
time: 20ms
memory: 23720kb

input:

99995
0 573954
1 101503
2 350026
3 832411
4 311022
5 583957
6 894954
7 223392
8 287704
9 259600
10 964702
11 24863
12 831166
13 754666
14 96743
15 606341
16 198920
17 262280
18 610409
19 193417
20 192417
21 194438
22 244016
23 680809
24 106449
25 249873
26 41805
27 375383
28 927874
29 148386
30 1354...

output:

0

result:

wrong answer 1st lines differ - expected: '50', found: '0'

Subtask #2:

score: 8
Accepted

Test #28:

score: 8
Accepted
time: 21ms
memory: 19228kb

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

24980330181

result:

ok single line: '24980330181'

Test #29:

score: 8
Accepted
time: 20ms
memory: 19500kb

input:

99997
0 122727
0 267270
0 846212
0 454122
0 805668
0 614161
0 7805
0 173284
0 684707
0 269129
0 930945
0 1101
0 992427
0 297412
0 759787
0 227130
0 120418
0 90914
0 333684
0 46144
0 519912
0 171490
0 823586
0 121787
0 674177
0 560254
0 753090
0 853359
0 465464
0 655527
0 631303
0 919012
0 597126
0 1...

output:

24980330181

result:

ok single line: '24980330181'

Test #30:

score: 8
Accepted
time: 25ms
memory: 19220kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #31:

score: 8
Accepted
time: 23ms
memory: 19376kb

input:

99998
0 792854
0 622829
0 836127
0 847372
0 71732
0 241096
0 487224
0 696890
0 899047
0 845614
0 27226
0 270985
0 698890
0 64699
0 856738
0 685434
0 766150
0 540443
0 802763
0 874879
0 250532
0 834015
0 616087
0 771638
0 262098
0 458015
0 959723
0 408130
0 880649
0 456673
0 923653
0 969100
0 439032
...

output:

1025006589524

result:

ok single line: '1025006589524'

Test #32:

score: 8
Accepted
time: 29ms
memory: 19344kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #33:

score: 8
Accepted
time: 33ms
memory: 19356kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Test #34:

score: 8
Accepted
time: 24ms
memory: 19328kb

input:

99997
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18302944415585093

result:

ok single line: '18302944415585093'

Test #35:

score: 8
Accepted
time: 28ms
memory: 19208kb

input:

99998
0 111160315429
0 355167263283
0 846519401525
0 697515481745
0 653176944193
0 975281743723
0 947695822588
0 443385029699
0 86490619914
0 542182758068
0 140914234365
0 453333219458
0 484226894553
0 930883160414
0 961277575066
0 392480084360
0 638524603170
0 806648354769
0 552428035490
0 99450464...

output:

18289278171456444

result:

ok single line: '18289278171456444'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 5
Accepted
time: 2ms
memory: 8592kb

input:

11
0 9
0 8
2 0
3 7
3 1
2 6
0 0
7 7
7 1
9 6
1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000

output:

1

result:

ok single line: '1'

Test #37:

score: 0
Wrong Answer
time: 12ms
memory: 13320kb

input:

50311
0 630582
1 458618
2 300543
3 566041
4 306718
5 134260
6 736322
7 458543
8 609374
9 355623
10 706939
11 48588
12 455725
13 105118
14 71071
15 528699
16 423538
17 471781
18 98063
19 169099
20 657181
21 295537
22 49937
23 306612
24 186582
25 505763
26 831500
27 406268
28 294626
29 128111
30 42115...

output:

0

result:

wrong answer 1st lines differ - expected: '813491', found: '0'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 12ms
memory: 13240kb

input:

50311
0 962897543825
1 887020369743
2 363658802934
3 481009844166
4 1099712574
5 858320882162
6 521927434762
7 379344260539
8 73024776148
9 634183458545
10 869560347910
11 81581323331
12 750044298516
13 307013017409
14 306226274039
15 423923546601
16 482114694167
17 849292461119
18 299993045938
19 7...

output:

0

result:

wrong answer 1st lines differ - expected: '939418184213', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%