QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116223#6659. 외곽 순환 도로 2youngsystem#0 27ms18472kbC++202.6kb2023-06-28 12:23:312024-05-31 18:21:37

Judging History

你现在查看的是测评时间为 2024-05-31 18:21:37 的历史记录

  • [2024-08-26 15:49:52]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:36ms
  • 内存:19632kb
  • [2024-05-31 18:21:37]
  • 评测
  • 测评结果:0
  • 用时:27ms
  • 内存:18472kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 12:23:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long dp[100005][2][2][2];
int dep[100005];
vector<int>v[100005];
vector<long long>qz[100005];
int n;
int yz[100005],cnt;
long long yq[100005];
int tl[100005],tr[100005];
long long nex[2][2][2];
void dfs(int x,int f)
{
	dep[x]=dep[f]+1;
	if(v[x].empty())
	{
		yz[++cnt]=x;
		tl[x]=tr[x]=cnt;
		return;
	}
	tl[x]=cnt+1;
	for(int i=0;i<v[x].size();i++)
	{
		dfs(v[x][i],x);
	}
	tr[x]=cnt;
}
void solve(int x,int f)
{
	if(v[x].empty())
	{
		dp[x][1][1][1]=0;
		return;
	}
	for(int i=0;i<v[x].size();i++)
	{
		//printf("???%d %d\n",x,v[x][i]);
		solve(v[x][i],x);
		if(i==0)
		{
			for(int j=0;j<=1;j++)
			{
				for(int k=0;k<=1;k++)
				{
					for(int l=0;l<=1;l++)
					{
						dp[x][j][k][l]=dp[v[x][i]][j][k][l];
						dp[x][0][0][l]=min(dp[x][0][0][l],dp[v[x][i]][j][k][l]+qz[x][i]);
					}
				}
			}
			continue;
		}
		for(int j=0;j<=1;j++)
		{
			for(int k=0;k<=1;k++)
			{
				for(int l=0;l<=1;l++)
				{
					nex[j][k][l]=1000000000000000000LL;
				}
			}
		}
		for(int j1=0;j1<=1;j1++)
		{
			for(int k1=0;k1<=1;k1++)
			{
				for(int l1=0;l1<=1;l1++)
				{
					for(int j2=0;j2<=1;j2++)
					{
						for(int k2=0;k2<=1;k2++)
						{
							for(int l2=0;l2<=1;l2++)
							{
								nex[j1][0][l1&l2]=min(nex[j1][0][l1&l2],dp[x][j1][k1][l1]+dp[v[x][i]][j2][k2][l2]+qz[x][i]);
								if(k1==0||j2==0)
								{
									nex[j1][k2][l1&l2]=min(nex[j1][k2][l1&l2],dp[x][j1][k1][l1]+dp[v[x][i]][j2][k2][l2]);
								}
								nex[j1][k2][0]=min(nex[j1][k2][0],dp[x][j1][k1][l1]+dp[v[x][i]][j2][k2][l2]+yq[tl[v[x][i]]-1]);
							}
						}
					}
				}
			}
		}
		for(int j=0;j<=1;j++)
		{
			for(int k=0;k<=1;k++)
			{
				for(int l=0;l<=1;l++)
				{
					dp[x][j][k][l]=nex[j][k][l];
				}
			}
		}
	}
}
long long place_police(vector<int> P, vector<long long> C, vector<long long> W)
{
	n=P.size();
	for(int i=0;i<n;i++)
	{
		v[P[i]+1].push_back(i+2);
		qz[P[i]+1].push_back(C[i]);
	}
	dfs(1,0);
	sort(yz+1,yz+cnt+1);
	for(int i=1;i<=cnt;i++)yq[i]=W[i-1];
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=1;j++)
		{
			for(int k=0;k<=1;k++)
			{
				for(int l=0;l<=1;l++)
				{
					dp[i][j][k][l]=1000000000000000000LL;
				}
			}
		}
	}
	//printf("orz\n");
	solve(1,0);
	long long ans=1000000000000000000LL; 
	for(int j=0;j<=1;j++)
	{
		for(int k=0;k<=1;k++)
		{
			for(int l=0;l<=1;l++)
			{
				ans=min(ans,dp[1][j][k][l]+yq[cnt]);
				if(j==1&&k==1)continue;
				if(l==1&&cnt%2==1)continue;
				//printf("%d %d %d %lld\n",j,k,l,dp[1][j][k][l]);
				ans=min(ans,dp[1][j][k][l]);
			}
		}
	}
	return ans;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

532281

result:

ok single line: '532281'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3852kb

input:

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

output:

729962

result:

wrong answer 1st lines differ - expected: '1000000110372', found: '729962'

Subtask #2:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 27ms
memory: 18472kb

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:

20631684589

result:

wrong answer 1st lines differ - expected: '24980330181', found: '20631684589'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 5
Accepted
time: 1ms
memory: 5956kb

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: 9ms
memory: 16040kb

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:

1836498

result:

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

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #77:

score: 0
Wrong Answer
time: 11ms
memory: 16260kb

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:

1347479397055

result:

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

Subtask #6:

score: 0
Skipped

Dependency #1:

0%