QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402760#6742. Leavesaltaires1#WA 3ms32224kbC++142.4kb2024-05-01 13:14:452024-05-01 13:14:47

Judging History

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

  • [2024-05-01 13:14:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:32224kb
  • [2024-05-01 13:14:45]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn=1100;

int n,m;

int into[maxn];

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<=siz[l];i++){
		for(int j=0;j<=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>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;
			into[l]++;
			into[r]++;
			to[i].push_back(l);
			to[i].push_back(r);
		}
		else{
			cin>>arrayA[i];
		}
	}
	int root=0;
	for(int i=1;i<=n;i++){
		if(into[i]==0){
			root=i;
			break;
		}
	}
	dfs1(root);
	dfs(root);
	for(int it : dp[root][m]){
		cout<<it<<' ';
	}
	cout<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 32012kb

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: 32012kb

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

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: 31948kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

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'