QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116245 | #6659. 외곽 순환 도로 2 | youngsystem# | 0 | 55ms | 20104kb | C++20 | 3.1kb | 2023-06-28 12:36:42 | 2024-08-26 15:50:00 |
Judging History
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;
int yd[100005];
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);
/*for(int j=0;j<=1;j++)
{
for(int k=0;k<=1;k++)
{
for(int l=0;l<=1;l++)
{
printf("orz%d %d %d %lld\n",j,k,l,dp[v[x][i]][j][k][l]);
}
}
}*/
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]);
nex[j1][0][0]=min(nex[j1][0][0],dp[x][j1][k1][l1]+dp[v[x][i]][j2][k2][l2]+qz[x][i]+yq[tl[v[x][i]]-1]);
if(k1==0||j2==0||(yd[tr[v[x][i-1]]]+yd[tl[v[x][i]]])%2==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]);
//if(nex[j1][k2][0]==8)printf("???%d %d %d %d %d %d %d %d\n",x,j1,k1,l1,j2,k2,l2,dp[v[x][i]][j2][k2][l2]);
}
}
}
}
}
}
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()+1;
for(int i=0;i<n-1;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],yd[i]=dep[yz[i]];
for(int i=0;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&&(yd[cnt]+yd[1])%2==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: 0
Wrong Answer
time: 0ms
memory: 5824kb
input:
5 0 452912 0 820899 0 79369 0 232463 1000000000000 1000000000000 1000000000000 1000000000000
output:
0
result:
wrong answer 1st lines differ - expected: '532281', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 55ms
memory: 20104kb
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:
0
result:
wrong answer 1st lines differ - expected: '24980330181', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 5
Accepted
time: 1ms
memory: 5932kb
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: 10ms
memory: 16840kb
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:
1487673
result:
wrong answer 1st lines differ - expected: '813491', found: '1487673'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 15ms
memory: 16336kb
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:
967490298273
result:
wrong answer 1st lines differ - expected: '939418184213', found: '967490298273'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%