QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307580 | #6659. 외곽 순환 도로 2 | hjl666 | 0 | 35ms | 17808kb | C++20 | 2.4kb | 2024-01-18 20:44:21 | 2024-08-26 15:51:48 |
Judging History
answer
#include<bits/stdc++.h>
#define db double
//#define int ll
#define ll long long
#define ull unsigned long long
#define pb emplace_back
#define MP make_pair
#define pii pair<int, int>
#define vec vector<int>
#define fi first
#define se second
#define ls k<<1
#define rs k<<1|1
#define CLK (double)clock()/(double)CLOCKS_PER_SEC
using namespace std;
mt19937 rnd(time(0));
inline int read(){
register int x=0,f=1;
register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void write(register int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
const int N=1e5+5;
int n,fa[N],val[N],circ[N],leaf,L[N],R[N],Dfn;
ll f[N][2][2][2],g[2][2][2];vector<pii> G[N];
void chkmin(ll &x,ll y){x=min(x,y);}
void dfs(int x,int fa){
f[x][0][0][0]=f[x][1][1][1]=0;
if(G[x].empty()){
L[x]=R[x]=++Dfn;
return ;
}
int son=0;
for(auto [y,w]:G[x]){
dfs(y,x);son++;
memcpy(g,f[x],sizeof g),memset(f[x],0x3f,sizeof f[x]);
for(int a=0;a<2;a++)for(int b=0;b<2;b++)for(int c=0;c<2;c++)
for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++){
if(son==1){
ll val=g[a][b][c]+f[y][i][j][k];
if(c==j)val+=circ[R[x]];
if(a==i)val+=w;
chkmin(f[x][a][j][k],val);
continue;
}
ll val=g[a][b][c]+f[y][i][j][k];
if(c==j)val+=circ[R[x]];
if(a==i)val+=w;
chkmin(f[x][a][b][k],val);//cerr<<x<<' '<<f[x][a][l][r]<<"\n";
}
if(!L[x])L[x]=L[y];R[x]=R[y];
// cout<<x<<' '<<y<<"\n";
// for(int a=0;a<2;a++)for(int b=0;b<2;b++)for(int c=0;c<2;c++)cout<<a<<' '<<b<<' '<<c<<' '<<f[x][a][b][c]<<"\n";
}
// cerr<<x<<' '<<L[x]<<' '<<R[x]<<"\n";
}
ll place_police(vector<int> P,vector<ll> C,vector<ll> W){
n=P.size()+1;
for(int i=2;i<=n;i++)fa[i]=P[i-2]+1,val[i]=C[i-2],G[fa[i]].pb(i,val[i]);
leaf=W.size();for(int i=1;i<=leaf;i++)circ[i]=W[i-1];
memset(f,0x3f,sizeof f);dfs(1,0);ll ans=0x3f3f3f3f3f3f3f3f;
for(int a=0;a<2;a++)for(int b=0;b<2;b++)for(int c=0;c<2;c++)
chkmin(ans,f[1][a][b][c]+(b==c?circ[leaf]:0));//cerr<<a<<' '<<b<<' '<<c<<' '<<f[1][a][b][c]<<"\n";
return ans;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12080kb
input:
5 0 452912 0 820899 0 79369 0 232463 1000000000000 1000000000000 1000000000000 1000000000000
output:
-2909519872
result:
wrong answer 1st lines differ - expected: '532281', found: '-2909519872'
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 35ms
memory: 17808kb
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:
-72735087280128
result:
wrong answer 1st lines differ - expected: '24980330181', found: '-72735087280128'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 2ms
memory: 12108kb
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:
-4364279801
result:
wrong answer 1st lines differ - expected: '1', found: '-4364279801'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 16ms
memory: 16044kb
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:
-27001798208618
result:
wrong answer 1st lines differ - expected: '939418184213', found: '-27001798208618'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%