QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402747#6742. Leavesaltaires1#WA 14ms32168kbC++142.3kb2024-05-01 12:19:312024-05-01 12:19:31

Judging History

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

  • [2024-05-01 12:19:31]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:32168kb
  • [2024-05-01 12:19:31]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn=1100;

int n,m;

int arrayA[maxn];

vector<int> dp[maxn][maxn];

vector<int> to[maxn];

int siz[maxn];

void dfs1(int a){
	if(to[a].empty()){
		siz[a]=0;
		return;
	}
	siz[a]=1;
	for(int it : to[a]){
		dfs1(it);
		siz[a]+=siz[it];
	}
	return;
}

void dfs(int a){
	if(to[a].empty()){
		dp[a][0].push_back(arrayA[a]);
		return;
	}
	int l=to[a][0];
	int r=to[a][1];
	dfs(l);
	dfs(r);
	for(int i=0;i<=min(siz[l],m);i++){
		for(int j=0;j<=min(m-siz[l],siz[r]);j++){
			//先左后右,表示没有交换
			vector<int> temp;
			int len=0;
			for(int it : dp[l][i]){
				temp.push_back(it);
				len++;
			}
			for(int it : dp[r][j]){
				temp.push_back(it);
				len++;
			}
			if(dp[a][i+j].empty()){
				for(int it : temp){
					dp[a][i+j].push_back(it);
				}
			}
			else{
				int judge=0;
				for(int k=0;k<len;k++){
					if(dp[a][i+j][k]<temp[k]){
						judge=-1;
						break;
					}
					else if(dp[a][i+j][k]>temp[k]){
						judge=1;
						break;
					}
				}
				if(judge==1){
					dp[a][i+j].clear();
					for(int it : temp){
						dp[a][i+j].push_back(it);
					}
				}
			}
			//先右后左,表示交换
			if(i+j+1>m||i+j+1>siz[a]){
				continue;
			}
			temp.clear();
			len=0;
			for(int it : dp[r][j]){
				temp.push_back(it);
				len++;
			}
			for(int it : dp[l][i]){
				temp.push_back(it);
				len++;
			}
			if(dp[a][i+j+1].empty()){
				for(int it : temp){
					dp[a][i+j+1].push_back(it);
				}
			}
			else{
				int judge=0;
				for(int k=0;k<len;k++){
					if(dp[a][i+j+1][k]<temp[k]){
						judge=-1;
						break;
					}
					else if(dp[a][i+j+1][k]>temp[k]){
						judge=1;
						break;
					}
				}
				if(judge==1){
					dp[a][i+j+1].clear();
					for(int it : temp){
						dp[a][i+j+1].push_back(it);
					}
				}
			}
		}
	}
	return;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int type;
		cin>>type;
		if(type==1){
			int l,r;
			cin>>l>>r;
			to[i].push_back(l);
			to[i].push_back(r);
		}
		else{
			cin>>arrayA[i];
		}
	}
	dfs1(1);
	dfs(1);
	for(int it : dp[1][m]){
		cout<<it<<' ';
	}
	cout<<'\n';
	return 0;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 32168kb

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: 0ms
memory: 31924kb

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: 4ms
memory: 31884kb

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: 3ms
memory: 31860kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 14ms
memory: 32140kb

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: 3ms
memory: 31936kb

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'