QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140755#6742. LeavesA_zjzjWA 2ms19684kbC++14845b2023-08-16 19:31:312023-08-16 19:31:32

Judging History

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

  • [2023-08-16 19:31:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:19684kb
  • [2023-08-16 19:31:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10,M=5e2+10;
int n,m,ls[N],rs[N],a[N],siz[N];
basic_string<int>f[N][M];
void dfs(int u){
	if(a[u]){
		f[u][0]+=a[u];
	}else{
		dfs(ls[u]),dfs(rs[u]);
		siz[u]=siz[ls[u]]+siz[rs[u]]+1;
		for(int i=0;i<=siz[ls[u]];i++){
			for(int j=0;j<=siz[rs[u]];j++){
				if(f[u][i+j].empty())f[u][i+j]=f[ls[u]][i]+f[rs[u]][j];
				else f[u][i+j]=min(f[u][i+j],f[ls[u]][i]+f[rs[u]][j]);
				if(f[u][i+j+1].empty())f[u][i+j+1]=f[rs[u]][j]+f[ls[u]][i];
				else f[u][i+j+1]=min(f[u][i+j+1],f[rs[u]][j]+f[ls[u]][i]);
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1,op;i<=n;i++){
		cin>>op;
		if(op==1)cin>>ls[i]>>rs[i];
		else cin>>a[i];
	}
	dfs(1);
	for(int x:f[1][m])cout<<x<<' ';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 19632kb

input:

3 0
1 2 3
2 1
2 2

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 19604kb

input:

7 1
1 2 3
1 4 5
1 6 7
2 4
2 2
2 3
2 1

output:

2 4 3 1 

result:

ok 4 number(s): "2 4 3 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 19680kb

input:

7 2
1 2 3
1 4 5
1 6 7
2 4
2 2
2 3
2 1

output:

1 3 4 2 

result:

ok 4 number(s): "1 3 4 2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 19684kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 2ms
memory: 19568kb

input:

3 1
1 2 3
2 1
2 2

output:

2 1 

result:

ok 2 number(s): "2 1"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 19680kb

input:

7 2
1 2 3
1 4 5
1 6 7
2 1
2 2
2 3
2 4

output:

2 1 4 3 

result:

wrong answer 1st numbers differ - expected: '1', found: '2'